2015년 12월 3일 목요일

Instantiate prefab as child of GameObject

go.transform.parent = transform; 를 하지 않으면,
Hierarchy Root 에 인스턴스(prefab) 이 생성된다.
따라서 기존의 Object Child 로 생성하려면 아래와 같이 하면 됩니다.

Source code for C#

protected GameObject slot_prefab = null;
for(int i = 0; i < max_slot_count; ++i)
{
GameObject go = GameObject.Instantiate(slot_prefab) as GameObject;
go.transform.parent = transform;
go.name = string.Format("{0:D2}", i);
_table_slot.Add(go.GetComponent<SdkListItem>());
}
view raw gistfile3.cs hosted with ❤ by GitHub

댓글 없음:

댓글 쓰기