Remove object from Array in javascript

Hello everyone, I have 4 spawn points in my game. What I want is, I made a huge invisible cube in front of my camera, and made it trigger. So it detects the spawn points in front of the player. ( note : as a spawn point, I used some objects which has collider in my level ) I want my code to check the spawn points which player does not see ( it will be detected by the collider object that is infront of my camera ) , and randomly choose one of that non seen by player spawn points. So I made a logic like that, I would remove the object which my collider touches from array and then go on RandomRange to the left objects in array. But I really have big problems about array, can some one help me with my code ?

#pragma strict

var spawns : GameObject;
var indx : int;


function OnTriggerEnter (c: Collider) {
if(c.tag=="Spawn")
{
indx = c.gameObject.GetComponent(SpawnScripts).id; // I made an int value for every spawn
// point so I'd know which spawn collider touches


spawns.RemoveAt (indx); // remove array, and here I got stuck
}

}

You don’t have any arrays in that code. Use a generic List:

import System.Collections.Generic;

var spawns : List.< GameObject >;
....

However your logic won’t work, since once you remove an object from the list, none of the IDs you have after that position in the list will point to the correct location in the list anymore. Since GameObjects are by reference you don’t need any ID, just remove that GameObject from the array directly. (i.e., use Remove instead of RemoveAt.)

Also, don’t declare variables outside functions unless they need to be global variables. So the “indx” variable should be declared inside OnTriggerEnter (not that you actually need it once you fix the code).