【发布时间】:2020-02-23 07:23:36
【问题描述】:
我有两个案例,无法弄清楚代码是如何工作的,请帮忙。谢谢
案例 1:
Transform[] zombiesTransform;
private void Start()
{
zombiesTransform = new Transform[5]; // now i have initialized so i can add some transform in it
// which is fine
}
案例 2:
Zombie[] zombies;
private void Start()
{
zombies = FindObjectsOfType<Zombie>(); // how is this zombie array is filled with value without
// initializing zombies variable like "zombies = new Zombies[5]"
}
【问题讨论】:
-
Becase FindObjectsOfType
在内部创建数组,然后将对该数组的引用返回给它的调用者。调用者(您的代码)将引用分配给您的数组变量。 -
@Steve 现在我明白了。谢谢