본문 바로가기

Programming/Unity3D

FindChild 간단 설명

자식의 GameObject 찾는 방법

1. 부모.transform.FindChild("자식이름");

2.GameObject.Find("/arm/hand/..../자식이름");

자신에게 바로연결되어있지않는 자식은 2번 방법으로 찾아야 된다.

또다른 방법.

자식의 자식의 자식...즉 손주뻘되는 GameObject를 찾을려면.

Transform[] allChilds;

Transform 자식;

void Start ()
 {
  allChilds = transform.GetComponentsInChildren<Transform>();
  int childCount = allChilds.Length;
      for(int i=0; i<childCount; i++)
      {
           if(allChilds[i].name == "자식이름") 자식= allChilds[i].transform;
      }

 }

으로도 찾을수있다.

간단히 설명하자면 allChilds배열을 선언후 모든 객체를 찾아서 배열에 담고.

그 배열의 길이값을 알아온뒤 for문으로 돌려서 찾고자 하는 자식이름을 넣고 찾으면 된다.

'Programming > Unity3D' 카테고리의 다른 글

RPG만들기 1-1 이동관련  (0) 2015.02.26
메모리 풀 클래스 만들어보기.  (0) 2015.02.24
Tower Defense 만들기 1장  (0) 2015.02.12
[앨] SkyBox  (0) 2015.01.19
[앨] 5. 간단한 탱크게임 만들기  (0) 2015.01.19