At Start function
private void Start()
{
spheres = GameObject.FindGameObjectsWithTag("MySphere");
lastPosition = spheres [0].transform.position;
}
lastPosition is Vector3 type
Then in the Update function:
private void Update()
{
UpdateSpheres();
MoveShips ();
}
And in the MoveShips now i have only one ship for the test:
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));
}
}
}
But when running the game it's never get into the Rotate line. I used a break point.