[英]Variables are not visible in script Inspector window
幾天前我開始使用 Unity,但我很困惑。
這是我當前的工作區:
這是應該的樣子:
我應該能夠填寫變量,但我不能。
要在檢查器中顯示屬性/變量,它們必須是public
,否則它們不會出現。
您還可以通過將private fields
歸屬為[SerializeField]
來查看private fields
。
要在檢查器中查看自定義類,您應該將它們標記為[Serializable]
。
要從檢查器隱藏公共變量,請使用[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 the 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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.