GameObject Array problem

Hi,

I've tried to write this function:

private function lookForBloc(isSpawn:boolean,faction:String,isBorder:boolean,borders:String){
    var result : GameObject;
    var resulTab : GameObject[];
    var number : int;
    for (bloc in blocs)
    {
        var BA = bloc.GetComponent("BlocAttributes");
        if(BA){
            if(BA.isSpawn == isSpawn && BA.isBorder == isBorder)
            {
                if(isBorder && BA.borders == borders )
                {
                    if(isSpawn && BA.faction == faction )
                    {
                        result = bloc;
                    }
                    result = bloc;
                }
            }
        }

    }
return result;
//~ number = Random.Range(0,resulTab.length);
//~ return resulTab[number];

}

But my problem is that i want an Array of results (as you can see in my comments) but when I try :

resulTab.Add(bloc);

or

resulTab[] = bloc;

or

resulTab *= bloc;*
*```*
*<p>It doesn't work, so I'd like to know how to store my GameObjects results in an Array.</p>*
*<p>Push doesn't work... I read that a List of GameObject would do it. But how can I declare one in JS ?*
*Thanks =D</p>*

1 Answer

1

Built-in arrays such as GameObject[] are fixed size, and the length can't be changed after the array is declared. (Before anyone mentions Array.Resize, that really just creates a new array and copies the contents.) For a dynamic array, use List, as in "`var resulTab : List.;`". (Make sure the script has "`import System.Collections.Generic`" in it.)

Thanks a lot =D