Transform[] childList = GameObject.GetComponentsInChildren<Transform>();

if (childList != null) {
	for (int i = 1; i < childList.Length; i++) {
		if (childList[i] != transform)
			Destroy(childList[i].gameObject);
	}
}

 

GameObject = 부모 오브젝트

for문에서 i=0 부터 시작하면 부모 오브젝트도 같이 삭제됨

 

 

'Study > Unity' 카테고리의 다른 글

[Unity] 안드로이드에서 뒤로가기  (0) 2021.07.26
[Unity] 게임 일시정지 기능  (0) 2021.07.26

+ Recent posts