[유니티] 모든 자식들 접근하기 2020.02.26 09:03 Game Programming/Unity Note 글 작성자: Coding Groot 유니티에서 간단하게 모든 자식들 접근하기 1. 선택한 게임 오브젝트 바로 아래에 있는 자식만 iterate하고 싶은 경우 foreach(Transform child in transform){ Debug.Log(child.name);} 2. 선택한 게임 오브젝트 아래에 있는 모든 자식을 iterate하고 싶은 경우 Transform[] allChildren = GetComponentsInChildren<Transform>();foreach(Transform child in allChildren) { // 자기 자신의 경우엔 무시 // (게임오브젝트명이 다 다르다고 가정했을 때 통하는 코드) if(child.name == transform.name) return; Debug.Log(child.name);} GetComponentsInChildren의 결과는 내 오브젝트 자신도 포함해서 반환하므로 자기 자신일 경우는 무시해줘야 한다. 출처 Unity Answer를 참고했습니다. https://answers.unity.com/questions/10417/how-can-i-access-the-children-of-a-transform.html How can I access the children of a Transform? - Unity Answers answers.unity.com Icons made by Freepik from www.flaticon.com 반응형 좋아요8공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기Coding Groot 댓글 공유하기 다른 글 댓글 Coding Groot코딩 블로그구독하기 댓글을 사용할 수 없습니다. 이 글 공유하기 구독하기 구독하기 카카오톡 카카오톡 라인 라인 트위터 트위터 Facebook Facebook 카카오스토리 카카오스토리 밴드 밴드 네이버 블로그 네이버 블로그 Pocket Pocket Evernote Evernote 다른 글 [유니티] SDK 경로 찾기 :: "Unable to detect SDK in the selected directory" [유니티] SDK 경로 찾기 :: "Unable to detect SDK in the selected directory" 2020.04.12 [유니티/C#] StringBuilder 정리 및 사용법 [유니티/C#] StringBuilder 정리 및 사용법 2020.02.26 [유니티] Bool 난수 생성하기 [유니티] Bool 난수 생성하기 2020.02.26 깔끔하게 Bool 난수 생성하는 법 예전에 본 코드인데 가끔 사용해서 노트로 남깁니다. Random.value를 써서 간단하게 구현할 수 있습니다. void Update() { bool randBool = (Random.value > 0.5f); Debug.Log(randBool); } 대표 이미지 출처: Icons made by Good Ware from www.flaticon.com [유니티] GameObject 없이 코드 실행하기 [유니티] GameObject 없이 코드 실행하기 2019.07.19 다른 글 더 둘러보기
댓글을 사용할 수 없습니다.