Emptying and filling Arrays on command? C#

Hi All,

I’m looking to solve a problem, and my understanding of arrays is not good enough to do so, here’s what I’m after:

An array which fills up with X number of GameObjects, any of which could be destroyed at any time. Under certain circumstances (let’s say, a button is pressed), I’d like to be able to fill up the empty spaces of the array with more GameObjects.

I don’t think it’s important but the objects will be randomly placed and will all be identical.

Is there some kind of array or combo of array & loop that can achieve this? I would imagine there is some way of filling all the empty positions in an array.

Thanks!

P.S I’m working in C#

Is that what you are looking for ?

GameObject[] array = new GameObject[x];

for(int i=0; i<array.Length; i++){

	if(array*==null){*

_ array = your game object_
* }*

}
_*You can find a great documentation about arrary in C# here : http://www.dotnetperls.com/array*_