https://docs.unity3d.com/kr/2019.4/Manual/ExecutionOrder.html
이벤트 함수의 실행 순서 - Unity 매뉴얼
Unity 스크립트를 실행하면 사전에 지정한 순서대로 여러 개의 이벤트 함수가 실행됩니다. 이 페이지에서는 이러한 이벤트 함수를 소개하고 실행 시퀀스에 어떻게 포함되는지 설명합니다.
docs.unity3d.com
-이벤트 함수의 실행 순서
? 연산자
값이 null인데 . (엑세스) 할려고 할때 Null Reference Exception이 발생 안하게 해준다.
그리고 null을 반환
-즉, Null이 아니라면 참조하고, Null이라면 Null로 처리
?? 연산자
- Null이라면 오른쪽 값으로 처리
=> if문을 사용해서 null 체크를 하다보면 코드가 길어지고, 가독성이 떨어지는 경우가 생길 때 사용한다.
멤버 액세스 및 null 조건부 연산자 및 식:
형식 멤버에 액세스하거나 null 조건부 액세스 형식 멤버에 사용하는 C# 연산자입니다. 이러한 연산자에는 점 연산자 '.', 인덱서 - '[', ']', '^' 및 '.가 포함됩니다. ', 및 호출 - '(', ')'.
learn.microsoft.com
부모 오브젝트의 자식을 받는 방법
Component.GetComponentInChildren
https://docs.unity3d.com/ScriptReference/Component.GetComponentsInChildren.html
GetComponentInChildren<T>(bool includInactive)는 컴포넌트를 T로 받아 자식을 찾는다.
-includeInactive 인자를 생략하면 false값이 반영된다. 즉, 비활성화된 게임오브젝트의 컴포넌트는 반환하지 않는다.
Transfor.GetChild(int index)
https://docs.unity3d.com/kr/530/ScriptReference/Transform.GetChild.html
-해당 게임 오브젝트의 자식 오브젝트는 순서대로(0 부터) 정수 값을 가지며,
정수 값에 해당하는 자식 오브젝트 Transform을 반환
관련 포스팅)
HeroShoot-Stage1 오류 수정: 자식 오브젝트 받기(GetComponentInChildren/GetChild)
-이전 포스팅에서 GetChild로 작성했을때 비활성화되어있던 target을 받아오려니 오류가 발생했는데 87~88라인과 같이 수정하여 해결하였다. GetComponentInChildren(bool includInactive)는 컴포넌트를 T로 받아
meltingmelvin.tistory.com
activeSelf/activeInHierachy
-A.activeSelf: A.SetActive(bool)에 영향을 받는다.
-A.activeInHierachy: A.SetActive(bool)에 따라 변하며, 부모의 active에 영향을 받는다. 자신보다 부모의상태를 먼저 따른다.
https://docs.unity3d.com/ScriptReference/GameObject-activeInHierarchy.html
Unity - Scripting API: GameObject.activeInHierarchy
Unlike GameObject.activeSelf, this also checks if any parent GameObjects affect the GameObject’s currently active state. When a parent GameObject is deactivated, its children are usually marked as active even though they are not visible, so they are stil
docs.unity3d.com
'C# 기초 복습' 카테고리의 다른 글
Quaternion.identity, LookRotation, 비트 연산자 (0) | 2023.08.21 |
---|---|
Unity- Coroutines(코루틴) (0) | 2023.08.08 |
2주차 복습 (0) | 2023.07.31 |
JSON예제, 대리자 복습 (0) | 2023.07.27 |
배열 예제 복습 (0) | 2023.07.25 |