I have an empty GameObject That Randomly selects a prefab out of 3 and then instantiates it, this works fine and it is always random, the problem is that it instantiates the next object immediately after the previous one, how do make so that there is a random amount of delay time before each object is instantiated. Help would be greatly appreciated.
Here is the Script attached to the empty Game Object;
var Cube1 : GameObject;
var Cube2 : GameObject;
var Cube3 : GameObject;
function Update()
{
var Delaytime: int = Random.Range(0,5)
yield WaitForSeconds(Delaytime);
var RandNum : int = Random.Range(1,4);
print(RandNum);
if(RandNum == 1)
{
Instantiate (Cube1,transform.position, transform.rotation);
}
if(RandNum == 2)
{
Instantiate (Cube2,transform.position, transform.rotation);
}
if(RandNum == 3)
{
Instantiate (Cube3,transform.position, transform.rotation);
}
}
Format code by selecting it and hitting the code button, please.
– Eric5h5