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!