Waiting for a certain amount of time

Hi! i am fairly new to this, in lua all I had to do to wait for a certain amount of time was type wait(), but I dont quite understand how to do this in unity. thanks for helping me out :stuck_out_tongue:

Here is what i have so far

var dropper : Transform;
function Update () {

var Cube : Transform;
Cube = Instantiate(dropper,
transform.position, transform.rotation);

}

But now i want it to wait a couple of seconds between spawning a cube.

yield WaitForSeonds ();

Also, be patient. Twelve minutes is not a long enough time to bump a post.

Wait for more than 12 minutes before bumping a topic, please. Anyway, you can use yield WaitForSeconds. The scripting docs have a search function; if you typed ā€œwaitā€, then you’d get WaitForSeconds as the third result.

Edit: er, beat to it. :wink:

–Eric

Thanks for the help, and sorry for being impatient. Now how would I get the whole thing to repeat at the end? I tried searching repeat on the documentation but I found nothing.

while(true) { yield return WaitForSeconds(N); do something after N seconds… repeat }

Infinite loops are so useful yet so unforgiving. I’ve had Unity crash multiple times because of them.

If you can wait until tomorrow, or you dont get any answers by then I can help

InvokeRepeating is what id go with… especially if that’s all you have in your update function, but that’s just me.

They are never a problem as long as you make sure that there is a yield.