0

GameObject在 Unity 中有一个应该用作某些定义的容器。

对象浏览器

我想访问该对象并检索Def类实例(每个对象都有Def通用类的实例)。

那么,如果我有一个GameObject实例,如何检索作为特定类实例的所有对象?

4

3 回答 3

1

您可以使用GameObject.GetComponents<Def>();检索Def中的所有类型组件GameObject
Unity 文档中的更多信息http://docs.unity3d.com/ScriptReference/GameObject.GetComponents.html

于 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 回答