2014-11-12 4 views
0

Unity에 일부 정의를위한 컨테이너 역할을하는 GameObject이 있습니다. 내가 그 개체에 액세스하고 Def 클래스 인스턴스를 검색하고 싶습니다GameObject에 포함 된 자식 개체의 배열을 얻는 방법

object explorer

은 (모든이 Def 일반 클래스의 인스턴스가 객체).

따라서 GameObject 인스턴스가있는 경우 특정 클래스의 인스턴스 인 모든 개체를 검색하려면 어떻게해야합니까?

답변

0
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 
0

에서
더 많은 정보를 원하시면만큼 당신이 GameObject 참조를 가지고 당신은 GetComponents()를 사용할 수 있습니다.

Def [] list = gameObject.GetComponents<Def>();