티스토리 뷰

두가지 방법이 있다.

 

1. 인덱스로 접근

transform.GetChild(int index)

 

위에서 부터 인덱스가 0,1,2 이다.

Floor1 // index 0

Floor2 // index 1

Floor3 // index 2

using UnityEngine;

public class NewBehaviour : MonoBehaiour {

	void Start() {
    // 첫 번째 child (Floor1)
    	GameObject child0 = transform.GetChild(0).gameObject;
    // 두 번째 child (Floor2)
        GameObject child1 = transform.GetChild(1).gameObject;
    }

}

 

 

2. child 오브젝트의 이름으로 접근

transform.Find("Object 이름")

 

using UnityEngine;

public class NewBehaviour : MonoBehaviour {

	void Start() {
    // Floor1
    	GameObject child1 = transform.Find("Floor1").gameObject;
        
    // Floor2
        GameObject child2 = transform.Find("Floor2").gameObject;
    }
}

'유니티' 카테고리의 다른 글

transform.position  (0) 2020.11.28
마우스 클릭한곳의 좌표, 오브젝트 생성  (0) 2020.10.09
UI 버튼 클릭안될때  (0) 2020.09.22
Rect Transform (Anchors, Pivot)  (0) 2020.08.13
GUI (Graphic User Interface)  (0) 2020.08.11
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/02   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
글 보관함