Default
By default, private privatep r i v a t e not displayed,public publicp u b l i c displays:
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
Through privatep r i v a t e add[S erialize F ield] [SerializeField]before or above[ S e r i a l i z e F i e l d ] allows us to observe the value of private variables:
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;
}
Space
[ S p a c e ] [Space] [ S p a c e ] can be found inI nspector InspectorAdd interlacing to the I n s p e c t o r view:
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;
}
Header
[ H e a d e r ( … … ) ] [Header(……)] [Header(…… ) ] Equivalent toInspector InspectorNotes (categories) under the I n s p e c t o r view:
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;
}
Range
[ R a n g e ( m i n , m a x ) ] [Range(min,max)] [ R a n g e ( m i n ,m a x ) ] can give anint, float int, floati n t , f l o a t variables limit the value range:
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
[ H i d e I n I n s p e c t o r ] [HideInInspector] [ H i d e I n I n s p e c t o r ] can make this variable not be displayed in theInspector InspectorIn the I n s p e c t o r panel, when you adjust a variable and do not want to modify it, you can hide it:
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;
}