|
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 sorry for my bad spelling :S and im Writing this in JavaScript
(comments are locked)
|
|
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. should probably be: if(array1[i] == obj)
Jun 01 '12 at 07:04 PM
gl03
(comments are locked)
|
|
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).
(comments are locked)
|
