|
Hello, What id like to do is Instantiate an array of Prefabs to an array of Spawn points. Say i have 5 prefabs in the objectsToSpawn Array, id like to spawn those prefabs at the array of spawnLocations.But say i have 6 spawnLocations i want to randomly select from my 5 objectsToSpawn and fill the 6 spawn points. Whats happening is it randomly selects from the prefabs and spawns 1 object in a random spawn point from the spawnLocations Array. Heres My Example Code:
//Objects To Spawn
var objectsToSpawn : GameObject[];
//Spawn Locations
var spawnLocations : Transform[];
function Spawn() {
//Select From Objects To Spawn
var thingToSpawn : int = Random.Range( 0, objectsToSpawn.length );
//Select From Spawn Locations
var placeToSpawn : int = Random.Range( 0, spawnLocations.length );
Instantiate( objectsToSpawn[thingToSpawn], spawnLocations[placeToSpawn].position,transform.rotation);
}
Sorry i cant be more clear but i hope You can understand what i am trying to do. Thanks for the help!
(comments are locked)
|
|
You can have another function (or modify the one you have) to sweep all spawnLocations and create a random prefab at each one:
function SpawnAllPoints() {
for (var i=0; i < spawnLocations.length; i++){
//Select From Objects To Spawn
var thingToSpawn : int = Random.Range( 0, objectsToSpawn.length );
Instantiate( objectsToSpawn[thingToSpawn], spawnLocations[i].position, transform.rotation );
}
}
It works just as id like it to thanks a ton man!
Oct 18 '11 at 02:08 AM
TripodGRANNE
(comments are locked)
|
