Spawn at random location (75% of the way there)

Hey guys, having a little trouble with my damn chickens spawning in my game. Trouble is, I need them to spawn at new locations every time the game is run (I know this can be done using arrays and I have declared an array at the top of my script ready). I have declared 6 spawn points and placed them into the array.

At the moment my script spawns the chickens at random locations in a set range. How would I go about changing this so instead of a random grid reference, they spawn at a random object listed in the array? (I know they are spawning because of the hierarchy). Here’s what I have so far:

var chicken : GameObject;
var spawnLocations : Transform[];

function Start() {
    var chickenNum = 3;
    for (var i = 0; i < chickenNum; i++){
        var position = Vector3(Random.Range(-10, 10), 0, Random.Range(-10, 10));
        Instantiate(chicken,position, Quaternion.identity);
     }
}

So instead of spawning at a random grid reference, how would I instantiate at a random gameobject I have set within the arrays? Any help is much appreciated! :slight_smile:

LOL you are simply making things complex

Here is a very simple script that instantiate car at random places

var car:GameObject;
var spawn:Transform[];

function Start(){
var spawnpos:Transform = spwan[Random.Range(0,spawn.length)];
Instantiate(car,spawnpos.position, spawnpos.rotation);
}

Sure
for the first one here is your script

var cars:Transform[];//you can also use GameObject[](eg.var cars:Array = new Array(gameObject.FindGameObjectsWithTag("car");
var spawn:Transform[];

function Start(){
for(var k =0 ;k<4;k++){ //allows to instantiate 4 enemies 
var car:Transform = car[Random.Range(0,car.length)];
var spawnpos:Transform = spawn[Random.Range(0,spawn.length)];
Instantiate(car,spawnpos.position,spawnpos.rotation);
}

}

in the second what did you mean 1.Did you mean to say that multiple enemies are not supposed to be instantiated at same time
or
did you mean you didnot want to instantiate second object in the same place after spawning 1st one