Engine/Unity

유니티 인스펙터 상에 보이지 않도록 [HideInInspector]

VirtualDever 2023. 2. 12. 13:55

멤버 변수를 public으로 해두고 유니티 인스펙터 상에 보이지 않게 하려면 아래 코드와 같이 [HideInInspector]를 추가해 주면 된다.

public class Player : MonoBehaviour {
    public static Player instance { get; private set; }

    [HideInInspector] public PlayerAnimation m_Animation;
    [HideInInspector] public PlayerStats m_Stats;
    [HideInInspector] public PlayerHealth m_Health;
    [HideInInspector] public PlayerInput m_UserInput;
    [HideInInspector] public PlayerInventory m_Inventory;
    [HideInInspector] public WeaponHandler m_WeaponHandler;
    [HideInInspector] public PlayerOutlineEffect m_OutlineEffect;

    void Awake() {
      instance = this;

      m_Animation = transform.GetComponent<PlayerAnimation>();
      m_Stats = transform.GetComponent<PlayerStats>();
      m_Health = transform.GetComponent<PlayerHealth>();
      m_UserInput = transform.GetComponent<PlayerInput>();
      m_Inventory = transform.GetComponent<PlayerInventory>();
      m_WeaponHandler = transform.GetComponent<WeaponHandler>();
      m_OutlineEffect = transform.GetComponent<PlayerOutlineEffect>();

      m_UserInput.enabled = true;
    }
  }

 

 

참고 문서

https://docs.unity3d.com/ScriptReference/HideInInspector.html

 

Unity - Scripting API: HideInInspector

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com