백지부터 시작하는 이세계 코딩 생활

GetComponentInChildren, GetComponentsInChildren 본문

백지부터 시작하는 이세계 유니티 생활 since 2020

GetComponentInChildren, GetComponentsInChildren

조아덕 2020. 11. 18. 16:46

함수이름에서 짐작할 수 있듯이, 특정 컴포넌트 ( Component ) 를 반환받기 위해서, 찾아오기 위해서 사용한다.

GetComponentInChildren

특정 컴포넌트의 하위(자식)객체 중 가장 선두에 존재하는 컴포넌트를 반환 시킨다.

GetComponentsInChildren 

특정 컴포넌트의 하위(자식)객체의 모두를 반환시킨다. 이때, 반환은 Array ( 배열 ) 형태로 반환된다.

 

Component 

GaemObject 의 기능적인 조각들을 의미한다.

Components오브젝트(objects)와 동작(behaviours)에 관한 너트와 볼트로 볼 수 있습니다.

GameObject는 다양한 컴포넌트들에 대한 컨테이너입니다. 기본적으로, 모든 GameObject는 자동으로 Transform 컴포넌트가 포함되어 있습니다. 이것은 Transform 컴포넌트에 의해 GameObject가 어디에 위치하고 있는지, 얼마나 회전하고 있는지, 어느 정도의 크기인지 결정되기 때문입니다. Transform 컴포넌트가 없다면 GameObject는 월드에 있을 곳이 없어져 버립니다

ex) Component


Ref. docs.unity3d.com/kr/530/Manual/UsingComponents.html


    private void Awake()
    {
        anim = GetComponentInChildren<Animator>();
        rb = GetComponent<Rigidbody>();
    }

 


Ref.

ldhwj.tistory.com/2

 

[Unity] GetComponentInChildren, GetComponentsInChildren

GetComponentInChildren, GetComponentsInChildren 두 메서드는 모두 자식 객체 중 특정 컴포넌트를 추출하는 기능을 한다. GetComponentInChildren 자식 객체 중 지정한 컴포넌트 하나만 추출하는데, 자식 객체가..

ldhwj.tistory.com

 

cru6548.tistory.com/5

 

[Unity] 특정 Object 찾는 법

 + 이 글은 작성자가 직접 공부하고 복습하며 작성한 글입니다. 만약 직접 작성하지 않았다면, 꼭 출처를 밝히겠습니다!  + 이 글은 개인적인 공부를 바탕으로 작성되었기에, 틀린 부분이 있을

cru6548.tistory.com

 

Comments