반응형
주의
자식 오브젝트는 씬에서 활성화되어 있어야합니다.
- 코드 작성 (GetComponentsInChildren 활용)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GetChild : MonoBehaviour
{
public Transform[] objList;
void Start()
{
objList = gameObject.GetComponentsInChildren<Transform>();
}
}
- 다른 방법 (자식 오브젝트를 여러개 가진 자식 오브젝트를 가져오는법)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class TransformPoint
{
public Transform[] transformList;
}
public class GetChild : MonoBehaviour
{
public Transform[] location;
public List<TransformPoint> listPoint = new List<TransformPoint>();
void Start()
{
for (int i = 0; i < location.Length; i++)
{
for (int j = 0; j < location[i].GetChild(0).childCount; j++)
{
TransformPoint point = new TransformPoint();
point.transformList = new Transform[location[i].GetChild(0).childCount];
for (int k = 0; k < 9; k++)
{
point.transformList[k] = location[i].GetChild(j).GetChild(k);
}
listPoint.Add(point);
}
}
}
}
참고할만한 글
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# NGUI 가변 해상도 대응 IOS 간단 사용법 (0) | 2022.08.28 |
---|---|
유니티 C# 가변 해상도 대응 Android , IOS 간단 구현 (0) | 2022.08.25 |
유니티 C# 베터리 잔량 가져오기 Battery 간단 사용법 (0) | 2022.08.25 |
유니티 C# 로컬 푸시 알림 Local Push Notification 간단 구현 (0) | 2022.08.17 |
유니티 C# 리소스 로드 Resource.Load 함수 간단 사용법 (0) | 2022.08.17 |
유니티 C# 애플 로그인 Sign ln with Apple Login 간단 구현 (0) | 2022.08.17 |
유니티 C# 비속어 필터 적용 inputfield 간단 사용법 (0) | 2022.07.14 |
유니티 C# 디버그 로그 종류 Debug.Log 간단 사용법 (0) | 2022.07.13 |
댓글