본문 바로가기

Game Programming/Unity

[Unity] getcomponentsinchildren 에서 부모(자기자신) 제외하는법

 

How to get all children without the parent?

Transform[] drawns = GetComponentsInChildren<Transform>() This include also the parent but i want to get only the children of the transform the script is connected. The problem is that it's

stackoverflow.com

위 문서 답변에 잘 정리돼있다.

(최고의 지식인. 누구신지 모르지만 무한한 감사드립니다.)

 

해결방법

public Transform[] spawnPoints;

spawnPoints = GetComponentsInChildren<Transform>().Where(t => t != transform).ToArray();

 

인덱스 0를 지우는 것보다 위 방법이 나은 것 같아 선택하였다.