SetActive(true or false)
- GameObject 자체의 활성화/ 비활성화 담당
- gameobject.SetActive(bool value);
activeSelf
- 현재 GameObject의 true, ffalse 값을 bool로 나타낸 것 + read only 전용
- GameObject.SetActive(true) 면 true, GameObject.SetActive(false) 면 false
- bool isActive = gameObject.activeSelf;
enabled
- GameObject 내에 있는 Component의 활성화/ 비활성화 담당
- gameobject.GetComponent<Component>().enabled = true or false;
SetActive vs enabled
- GameObject 전체를 활성화 / 비활성화 or Gameobject내의 Component를 활성화 / 비활성화 하느냐의 차이
OnEnable
- 활성화 (= gameobject.SetActive(true)) 될 때마다 초기화 되면서 호출되는 함수 + Start() 함수 전에 실행
- Start함수와의 차이
- Start() : 최초 실행 1번만 초기화
- OnEnable() : 호출될 때마다 초기화
- 실행 순서: OnEnable -> Start -> Update
OnDisable
- 비활성화 (= gameobject.SetActive(false)) 될 때마다 초기화되면서 호출되는 함수
※ (OnEnable 과 OnDisable은 Inspector창의 체크박스 담당)
'C#, Unity' 카테고리의 다른 글
| C#, Unity) 애니메이션 GetCurrentAnimatorStateInfo (2) | 2024.11.10 |
|---|---|
| C#, Unity) IEnumerator, Coroutine, Lerp 함수 (1) | 2024.08.12 |
| C#, Unity) Array - Remove Functions (0) | 2024.08.02 |
| C#, Unity) 범위 안 Enemy 판별 (1) | 2024.07.13 |