Unity
[Unity3D] 자식 오브젝트 찾기
Aducssini
2019. 6. 26. 03:23
대략 2가지로 이야기들 하는 듯하다.
첫째로
transform.GetChild("'Index");
1
2
3
4
5
6
7
8
9
10
11
|
public class NewBehaviourScript : MonoBehaviour
{
public Transform transformChild;
private void Start()
{
transformChild = transform.GetChild(0);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
|
GetChild(0) 은 첫번째.
GetChild(1) 은 두번째.
GetChild(2) 은 세번째를 반환한다.
참고로 반환형은 Transform 이다.
두번째는
transform.find("name") 이다.
GameObject.find("name") 과 다른 점은
GameObject.find("name")은 모든 오브젝트를 찾는 반면에
transform.find("name") 은 자식 오브젝트를 찾는다고 한다.
1
2
3
4
5
6
7
8
9
10
|
public class NewBehaviourScript : MonoBehaviour
{
public Transform transformChild;
private void Start()
{
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5; text-decoration:none">Colored by Color Scripter
|
하지만 역시 string으로 찾는 건 은근히 거부감이 드는것은 사실이다.