Hello, I have thrown together a random spawning script, however i would like it to be a bit more complicated. At the moment i have a spawn point being chosen at random however, that the chose spawn point will only ever spawn the same object. Here is what i have so far:
var timer : float = 0.0;
var spawning : boolean = false;
var meteor1 : Rigidbody;
var meteor2: Rigidbody;
var meteor3 : Rigidbody;
var spawn1 : Transform;
var spawn2 : Transform;
var spawn3 : Transform;
function Update () {
if(!spawning){
timer += Time.deltaTime;
}
if(timer >= 1.5){
Spawn();
}
}
function Spawn(){
spawning = true;
timer = 0;
var randomPick : int = Mathf.Abs(Random.Range(1,4));
var location : Transform;
var whichObj : Rigidbody;
if(randomPick == 1){
location = spawn1;
whichObj = meteor1;
Debug.Log("Chose pos 1");
}
else if(randomPick == 2){
location = spawn2;
whichObj = meteor2;
Debug.Log("Chose pos 2");
}
else if(randomPick == 3){
location = spawn3;
whichObj = meteor3;
Debug.Log("Chose pos 3");
}
var meteorToMake : Rigidbody = Instantiate(whichObj, location.position, location.rotation);
meteorToMake.AddForce(-Vector3(0,0,500));
yield WaitForSeconds(1);
spawning = false;
}
What I would like is to also choose the object that spawns from the spawn point randomly…
Any ideas?