for (int x = 0; x < mapLength; x++)
{
var instantiateMap = new Vector3(x * 2, 0, 1);
GameObject[] cubeObjectClones = Instantiate(cubeObject, instantiateMap, Quaternion.identity) as GameObject;
cubeObjectClones[x].transform.parent = transform;
}
无法隐式转换类型UnityEngine.GameObject' to
UnityEngine.GameObject []&#39;
有人可以解释我如何解决这个错误吗?
答案 0 :(得分:5)
这是因为Instantiate方法返回单个GameObject。相反,您需要使用循环来生成更多实例并将它们添加到数组中。请使用以下代码。
class:before and class:after