unity-game-engineunityscript

What are my errors in the following code?


This is the function:

for (i = 0; i <= array.Length; i++) {
      if (array[i].transform.position = 0)
        array.RemoveAt(i);
        print(“Removed element: “ + array[i].name);
      else if (array[i].transform.position > 0)
         array[i].transform.forward = Vector3(1,0,0);
}

Solution

  • You can't compare a vector to 0, it needs to be like this:

    if (myObject.transform.position == Vector3.zero)
    

    and for removing things I'd suggest to include System.Collections.Generic lib, then use List<GameObject> array then you can use array.RemoveAt(index);