0

UnityにGameObjectは、いくつかの定義のコンテナーとして機能するはずの があります。

オブジェクト エクスプローラー

Defそのオブジェクトにアクセスして、クラス インスタンスを取得したいと思います (そこにあるすべてのオブジェクトはDef一般クラスのインスタンスです)。

GameObjectでは、インスタンスがある場合、特定のクラスのインスタンスであるすべてのオブジェクトを取得するにはどうすればよいでしょうか?

4

3 に答える 3

1

を使用して、内のタイプのGameObject.GetComponents<Def>();すべてのコンポーネントを取得できます。 Unity ドキュメントの詳細情報http://docs.unity3d.com/ScriptReference/GameObject.GetComponents.htmlDefGameObject

于 2014-11-12T17:48:48.210 に答える
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
于 2014-11-12T21:13:54.933 に答える
0

GameObject参照がある限り、GetComponents()を使用できます。

Def [] list = gameObject.GetComponents<Def>();
于 2014-11-13T07:05:08.363 に答える