Hi guys. I'm kind of new to this. I want cubes to spawn randomly in the game every, let's say, 5 seconds. I have this code so far:
var object:Transform;
var x = 12;
var z = 12;
var y = 5;
function Update () {
var position = Vector3(Random.Range(-x, x), y, Random.Range(-z, z));
Instantiate(object, position, Quaternion.identity);
}
I tried using yield WaitForSeconds(5.0) but it messed things up... Thank you in advance.
you can't use yield in Update(). you should do it in start(), Awake() or custom functions like this:
function Start(){
DoInstantiate();
}
function DoInstantiate(){
while (true){
yield WaitForSeconds(5.0);
var position = Vector3(Random.Range(-x, x), y, Random.Range(-z, z));
Instantiate(object, position, Quaternion.identity);
}
}