我想在场景中放置六个物体(球)。我认为代码看起来可行,但我收到一条控制台消息。消息:
“Assets/GameScripts/Instance.cs(26,40):错误 CS0266:无法隐式转换类型
object' to
UnityEngine.Vector3'。存在显式转换(您是否缺少演员表?)”
使用 UnityEngine;使用 System.Collections;
公共类实例:MonoBehaviour {公共游戏对象球;
public ArrayList coordinateContainer = new ArrayList();
// Use this for initialization
void Start () {
coordinateContainer.Add(new Vector3(1f,1f,1f));
coordinateContainer.Add(new Vector3(2f,1f,1f));
coordinateContainer.Add(new Vector3(3f,1f,1f));
coordinateContainer.Add(new Vector3(4f,1f,1f));
coordinateContainer.Add(new Vector3(5f,1f,1f));
coordinateContainer.Add(new Vector3(6f,1f,1f));
//ball.transform.position = new Vector3(1f,1f,1f);
ball.transform.rotation = Quaternion.identity;
for (int i = 0; i < 6; i++) {
ball.transform.position = coordinateContainer[i];
Instantiate(ball,ball.transform.position,ball.transform.rotation);
}
}
// Update is called once per frame
void Update () {
}
}