I need to run a task 10 times per second throughout the entire game. Is it possible to do this using co routines. I dont really understand them or should i just use some sort of timer with an if statement.
It is either :
Or :
public var frequency : float = 0.1;
private var frequencyCountdown : float = 0.0;
function Update ()
{
frequencyCountdown += Time.deltaTime;
if (frequency <= frequencyCountdown)
{
frequencyCountdown = 0.0;
PeriodicTask ();
}
}
function PeriodicTask ()
{
// stuff obese chickens
}
THANK YOU!!! Both solutions work great.
His solution works fine, but if the game does down to less than 10 fps (or you need it to happen faster) than his method may miss a few.
GMLastUpdate += Time.deltaTime;
for(i = GMLastUpdate / GMUpdate ; i >= 1 ; i-= 1){
GMLastUpdate -= GMUpdate;
}
Thats great!