프로그래밍/유니티
[유니티] GetComponentsInChildren 주의점
NIA1995
2022. 2. 2. 22:55
해당 함수를 사용하면 자식 오브젝트 뿐만 아니라 본인 오브젝트에 포함된 컴포넌트도 가져옵니다. 따라서 사용시에 주의해서 사용해야 합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Smf : Stat Modifier Feature */
public class Smf : MonoBehaviour
{
public string itemName;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Consume : MonoBehaviour
{
public Smf[] smfList;
void Start()
{
smfList = gameObject.GetComponentsInChildren<Smf>();
}
}