0

我是 Unity 的新手。

我有一个我声明使用的 GameObjects 数组

var shades:GameObject[];

现在,我必须使用将其转换为数组

var allShades =new Array(shades);

但似乎gameObjects已经转入Objects,因为我不能再使用了,例如

allShades[index].GetComponent(MyScript);

它给了我这个错误:'GetComponent'不是'Object'的成员

我什至不确定我在这里所做的所有事情,呵呵!

我一直在谷歌搜索,但我找不到解决方案。

有什么帮助吗?谢谢!:)

4

1 回答 1

0

不,您不能使用.GetComponent,因为allShades它是一个数组(并且数组是一个对象)而不是GameObject. 您需要首先使用它访问GameObject它的内部allShades[index],然后您可以使用.GetComponent

参见Unity Reference about Arrays

于 2014-08-14T19:04:38.730 回答