Unity에 일부 정의를위한 컨테이너 역할을하는 GameObject
이 있습니다. 내가 그 개체에 액세스하고 Def
클래스 인스턴스를 검색하고 싶습니다GameObject에 포함 된 자식 개체의 배열을 얻는 방법
은 (모든이 Def
일반 클래스의 인스턴스가 객체).
따라서 GameObject
인스턴스가있는 경우 특정 클래스의 인스턴스 인 모든 개체를 검색하려면 어떻게해야합니까?
Unity에 일부 정의를위한 컨테이너 역할을하는 GameObject
이 있습니다. 내가 그 개체에 액세스하고 Def
클래스 인스턴스를 검색하고 싶습니다GameObject에 포함 된 자식 개체의 배열을 얻는 방법
은 (모든이 Def
일반 클래스의 인스턴스가 객체).
따라서 GameObject
인스턴스가있는 경우 특정 클래스의 인스턴스 인 모든 개체를 검색하려면 어떻게해야합니까?
GameObject.GetComponents<Def>();
을 사용하여 Def
유형의 모든 구성 요소를 GameObject
에 검색 할 수 있습니다. 유니티 문서 http://docs.unity3d.com/ScriptReference/GameObject.GetComponents.html
public Def[] defArray;
public Defs gameobject; ///if you want to access from another class assign this your Defs gameobject from inspector
defs = Defs.GetComponents<Def>(); ///if you want access from another game object
defs = gameObject.GetComponents<Def>(); ///if Defs is attached to this gameObject
에서
더 많은 정보를 원하시면만큼 당신이 GameObject
참조를 가지고 당신은 GetComponents()를 사용할 수 있습니다.
Def [] list = gameObject.GetComponents<Def>();