¿how can I enter values in a GameObect[] dinamically?

I am trying to enter values dinamically in a GameOBject var, but I can´t.

I have some enemies in that array, and when they are Destroyed, I want to enter more from other GameObject, but I don´t know how


how about something like:

for(var i = 0;i < myObjectArray.length;i++){

myObjectArray = Instantiate( myOtherObjectArray[Random.Range(0,myOtherObjectArray.length)],transform.position,transform.rotation;
just an example, this instantiates all the objects at the location of the object with this script, you’ll need to update that part based on your needs…
(I am assuming you mean to CLONE objects from the other array, and my example does so RANDOMLY)

Unless you want to always have the same number of enemies on the screen, I would suggest using 1 if you are not comfortable with using built-in arrays.

List<GameObject> enemies = new List<GameObject>();

GameObject enemy = Instantiate(someEnemyPrefab);

enemy = null;

Note that fixed-size built in arrays are slightly faster, but also much more difficult to work with.

thank you so much, I have fixed my problem totally :wink: