2016-09-28 316 views
1

几天前我开始了Unity,而且我很困惑。
这是我目前的工作区:公共变量在脚本Inspector窗口中不可见

这是什么是应该是这样的:

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

如果你想在这里看到的脚本

是膏状斌:http://pastebin.com/qgiewjAK

+0

是否董事会经理包含任何相关的代码?它看起来像内省失败 - 或者更可能是它缺少代码(或未保存的代码)。 –

+0

我有公共变量,但我仍然有相同的错误。 –

+0

你能展示一些代码吗? –

回答

0
  1. 要显示的属性/在检查变量,它们必须public,如果他们不,他们将不会出现。

  2. 您也可以将private fields归类为[SerializedField]

  3. 要查看检查器中的自定义类,应将它们标记为[Serializable]

  4. 要从检查员隐藏公共变量,请使用[HideInInspector][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; 
} 
+0

我有公共变量,但我仍然有相同的错误。 :( –

+0

什么错误?请把你的脚本问题 –

+0

以来我都没有错误。 –