その先にあるもの…

NGUITools.AddChild 본문

프로그래밍/Unity

NGUITools.AddChild

specialJ 2013. 12. 5. 17:40

객체를 생성하여 다른 객체의 자식으로 추가 시킬 경우



static public GameObject AddChild (GameObject parent, GameObject prefab)
{
	GameObject go = GameObject.Instantiate(prefab) as GameObject;
	if (go != null && parent != null)
	{
		Transform t = go.transform;
		t.parent = parent.transform;
		t.localPosition = Vector3.zero;
		t.localRotation = Quaternion.identity;
		t.localScale = Vector3.one;
		go.layer = parent.layer;
	}
	return go;
}


t.parent = parent.transform


이 코드만 사용해도 객체 자식으로 추가 되지만 NGUI에서는


transform값 등에 쓰레기값 같은 것들이 들어가는 경우가 종종 발생한다.

'프로그래밍 > Unity' 카테고리의 다른 글

Animation Read-Only  (0) 2014.02.11
unity animator event  (0) 2013.12.05
Prefab SetActive(false)시 스크립트 접근이 안되는 경우1  (0) 2013.12.05
NGUI 객체 피킹  (0) 2013.12.05
AssetBundle  (0) 2013.10.29
Comments