公共变量在脚本检查器窗口中不可见

时间:2016-09-28 10:50:05

标签: c# unity3d

我几天前开始使用Unity,我很困惑。
这是我当前的工作区:

这应该是这样的:

我应该能够填写变量,但我不能。

如果您希望此处的脚本是粘贴框:http://pastebin.com/qgiewjAK

1 个答案:

答案 0 :(得分:0)

  1. 要在检查器中显示属性/变量,它们必须为public,如果它们不是它们不会出现。

  2. 您还可以通过将private fields归为[SerializedField]来查看[Serializable]

  3. 要在检查器中查看自定义类,您应将其标记为[HideInInspector]

  4. 要隐藏检查员的公共变量,请使用[System.NonSerialized]public class SomePerson : MonoBehaviour { //This field gets serialized because it is public. public string name = "John"; //This field does not get serialized because it is private. private int age = 40; //This field gets serialized even though it is private //because it has the SerializeField attribute applied. [SerializeField] private bool hasHealthPotion = true; // This will be displayed in inspector because the class has Serialized attribute. public SomeCustomClass somCustomClassInstance; // This will not be shown in inspector even if it is public. [HideInInspector] public bool hiddenBool; // Same with this one. [System.NonSerialized] public int nonSerializedVariable = 5; } [System.Serializable] public class SomeCustomClass { public string someProperty; } 属性。

  5. 以下是一个示例:

    <script>
            $(function () {
    
                $('input[type=radio]').on('click', function () {
    
                    var value = $(this).attr('value');
                    console.log(value);
                    if ($(this).is(':checked')) {
                       // alert("it's checked");
                        console.log("it's checked");
                    }
                });
            });
        </script>