Find GameObjects With different Tag

Hi! I need find GameObjects With different Tag and put it in the one array, i’ll try do it this way: (but it write me, that “Array index is out of range”)

var waypoints: GameObject[] ;
var player2: GameObject[] ;
var player3: GameObject[] ;

function Update () {

    player2 = GameObject.FindGameObjectsWithTag("Player2"); 
    player3 = GameObject.FindGameObjectsWithTag("Player3"); 
       
    waypoints[0] = player2[0] ; //Error here: Array index is out of range
    waypoints[1] = player3[0] ;
    
}

Maybe anyone know other way how can i do this?

Like whydoidoit said, the array needs to be initialized. Change

var waypoints: GameObject ;

to

var waypoints: GameObject = new GameObject[2];

For a 2 position builtin arrays. You can also initialize by the editor (put a size number like 2) or use non-fixed size arrays too.

var waypoints: GameObject ;
var player2: GameObject ;
var player3: GameObject ;

function Update () {

    player2 = GameObject.FindGameObjectsWithTag("Player2"); 
    player3 = GameObject.FindGameObjectsWithTag("Player3"); 

    waypoints = new GameObject[player2.length + player3.length];

    waypoints[0] = player2[0] ; //Error here: Array index is out of range
    waypoints[1] = player3[0] ;

}