- Home /
Question by
NinjaRubberBand · Feb 18, 2014 at 05:06 PM ·
spawneventyield
Make a event happen every 4 seconds?
How do i make something happen every 5 seconds? I have this script that spawns a object at start. But i want it to spawn a object every 5 second. How do i implement it?
#pragma strict
var rndNum:int;
var less = 5;
var asteroid : Transform;
var myposition : GameObject;
var spawn = true;
function Start() {
Instantiate(asteroid, myposition.transform.position, myposition.transform.rotation);
}
Comment
Best Answer
Answer by whydoidoit · Feb 18, 2014 at 05:08 PM
You can use InvokeRepeating to make a function occur at regular intervals.
Or you could use a for next or while loop and yield WaitForSeconds:
function Start() {
while(true) {
Instantiate...
yield WaitForSeconds(4);
}
}
Your answer
Follow this Question
Related Questions
Best way to wait for event inside Coroutine? 3 Answers
spawn an object using yield/startCoroutine 2 Answers
Event-based spawning 1 Answer
Architecture for a network game- problems with events 0 Answers