Unity重命名公共字段以保留分配 [英] Unity rename public fields to keep assignments

查看:106
本文介绍了Unity重命名公共字段以保留分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Unity脚本中重命名字段,但将其分配保留在Unity Editor检查器中? 说我有

how can I rename a field in a Unity script, but keep it's assignment in the Unity Editor inspector? Say I have

public int x;

我将inspctor中的x分配为"1",然后在脚本中将x重命名为y.作业将丢失.有没有办法保留它?

I assign "1" to x in the inspctor and then i rename x to y in the script. The assignment will then be lost. Is there a way to keep it?

我正在使用Visual Studio.

I'm using Visual Studio.

推荐答案

执行以下操作会将值保存在检查器中.再次保存场景后,可以将其删除.

Doing the following will save the value in the inspector. It can be removed after the scene has been saved again.

[FormerlySerializedAs("x")]
public int y;

在此处详细了解 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆