hi i want to know how i can add an gameobject to a Array when the gameObject is created i want to have a command that add the object to a spesific array in another Script file
and if the gameObject is Desroyed remove him from the Array and fix the Array what i mean is if the Array has 5 entrys and entry 3 is Desroyed i want entry 4 to be 3 and 5 to be 4
You can pretty easily go about adding and subtracting from an array, here's an example
And as far as subtracting a gameObject goes you could try removing it from the array before you destroy it.
answered Mar 19 '10 at 08:45 PM
There is no "Add" method on the builtin array type! The above will not compile, even if you do use "GameObject" instead of "gameObject".
However, try this:
Voila! Note that this is less efficient than implementations such as a fixed-maxsize array with an end cursor, but I tend to use it when the adding to the array is not performance-critical (eg. bullet is created), thus making it easy to use these fast builtin arrays, so that the performance critical array-READING code (eg. for every bullet every frame, check for hits).
answered Jun 21 '11 at 11:26 AM