Gameobject array
Hello, I recently hit a wall, and even if I found an alternative, I would like to know how to do it this way.
Imagine we have an empty GameObject called "floor". This one instantiates children GameObjects as cubes, which are stored in an array : While...{ floorCell[I] = Instantiate(prefab,...)}
These cells are moving (downward referring to the player), and when they arrive behind the player I would like them to disappear, and the array to adapt itself : While...{ floorCell[I] = floorCell [I+1]} floorCell[endOfArray] = Instantiate...
If I do it this way, it works, but each time the first GameObject stays, and accumulate each time. If in the while loop I add : Destroy(floorCell[I].gameObject) I end up with an error saying I can't manipulate GameObjects not existing.
Mainly practising C, I'm used to create arrays and manipulate pointers, but in C# and unity I don't really know how to adapt myself :P
Thanks in advance for your help :)
To access the first gameobject of the array, you have to use floorCell[0] (cause the first object in a array/list/transform hierarchy is always 0 and not 1). So, if your first element stays, it seems you start destroying the gameobjects by floorCell[1] ins$$anonymous$$d floorCell[0].
Check that...
I didn't wan't to be annoying with long code samples (by the way my array is actually 2 dimensional, but it was simpler to explain this way), but it looks like that :
if(the first block [0] gets behind){ for(int i=0; i
I don't know if you see the entire message, it looks like it was cut off, I'm using the mobile site version and it's not always working well...