0

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.

TheLost Lostit
  • 505
  • 6
  • 28
  • 1
    Did you debug and check that `distanceTravelled` ever gets to `30`? I assume you are looking for ` if (distanceTravelled >= 30)` – Gilad Green Oct 07 '16 at 12:05
  • 2
    As said in another comment, you need to compare with >=, You are comparing floats, the distance will (very likely) never be EXACTLY 30. See this question : http://stackoverflow.com/questions/39898301/if-statement-not-working-checking-float-value/39898363#39898363 – Riaan Walters Oct 07 '16 at 12:08

0 Answers0