デフォルト
デフォルトでは、プライベートプライベートp r i v a t eは表示されません、一般公開p u b l i cの表示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
private Rigidbody2D rigidbody2D;
private Animator animator;
public float speed = 5f;
public float jumpForce = 5f;
}
SerializeField
プライベートを通じてp r i v a t e add[Serialize Field] [SerializeField]before or above[ S e r i a l i z e F i e l d ]を使用すると、プライベート変数の値を観察できます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private Rigidbody2D rigidbody2D;
private Animator animator;
public float speed = 5f;
public float jumpForce = 5f;
}
スペース
[Sペース] [スペース] [ Sは、P 、A 、C 、E ]に見出すことができるI nspectorインスペクタインターレース追加I N S P E C T O Rビュー:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private Rigidbody2D rigidbody2D;
private Animator animator;
[Space]
public float speed = 5f;
public float jumpForce = 5f;
}
ヘッダ
[H eader(……)] [Header(……)] [ H e a d e r (…… )] InspectorInspectorと同等I n s p e c t o rビューの下のメモ(カテゴリ):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private Rigidbody2D rigidbody2D;
private Animator animator;
[Header("速度设定")]
public float speed = 5f;
public float jumpForce = 5f;
}
範囲
[範囲(最小、最大)] [範囲(最小、最大)] [ R a n g e (m i n 、m a x )]は、int、float int、floatを与えることができますi n t 、f l o a t変数は、値の範囲を制限します。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private Rigidbody2D rigidbody2D;
private Animator animator;
[Header("速度设定")]
[Range(3f,7f)]
public float speed = 5f;
public float jumpForce = 5f;
}
HideInInspector
[Hide I n I nspector] [HideInInspector] [ H i d e I n I n s p e c t o r ]は、この変数をインスペクターインスペクターに表示しないようにすることができますI n s p e c t o rパネルで、変数を調整し、それを変更したくない場合は、次のように非表示にできます。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private Rigidbody2D rigidbody2D;
private Animator animator;
[Header("速度设定")]
[Range(3f,7f)]
public float speed = 5f;
[HideInInspector]
public float jumpForce = 5f;
}