Study/Unity
[Unity] 자식 오브젝트 찾아서 모두 삭제하기
성으니:)
2021. 8. 6. 07:17
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 부터 시작하면 부모 오브젝트도 같이 삭제됨