启动功能
private void Start()
{
spheres = GameObject.FindGameObjectsWithTag("MySphere");
lastPosition = spheres [0].transform.position;
}
lastPosition是Vector3类型
然后在更新功能中:
private void Update()
{
UpdateSpheres();
MoveShips ();
}
现在在MoveShips中,我只有一艘船用于测试:
private void MoveShips()
{
foreach (Transform child in spheres[0].transform)
{
child.transform.position += Vector3.forward * Time.deltaTime * moveSpeed;
distanceTravelled += Vector3.Distance (child.transform.position, lastPosition);
if (distanceTravelled == 30)
{
child.transform.Rotate(new Vector3(0f,180f,0f));
}
}
}
但是在运行游戏时,它永远不会进入旋转线。 我用了一个断点。