- Home /
Delay in a cycle
I basically want to cycle between 2 states and make it wait for a second each time, before entering state 2. like: enter state 1 - wait for a second. enter state 2 - skip it(I'll put a code here soon) then loop
var state = 1; var delayBetweenStates = 1; function Cycle(){ if(state==1){ var nextState = 0.0; nextState += Time.time; if(nextState >= delayBetweenStates){ print("advancing from 1"); state++; } }
if(state==2){
print("wrapping to 1");
state= 1;
}
}
function Update(){ Cycle(); }
what this code does is that it waits for a moment, the first time it goes through state 1, then keeps constantly skipping.
var state = 1; var stateDelay = 1; var nextStateTime = 0;
function Cycle(){ if(state==1){ if(Time.time > nextStateTime){ print("advancing from 1"); nextStateTime = Time.time + stateDelay; state++; } }
if(state==2){ print("wrapping to 1"); state= 1; }
}
this code doesn't help neither.
Any idea how to achieve such results?
Answer by dot · Sep 28, 2010 at 09:44 PM
oh. actually it did... forgot to use
function Update(){ Cycle(); }
in the edited version. eh.
Your answer

Follow this Question
Related Questions
Long delay between pressing play and before Profiler begins recording 1 Answer
Why do await Task.Delay(10); stops execution in unity Web-GL? 1 Answer
animation delay or wait 4 Answers
Raycast Delay 3 Answers
How to make an enemy respawn? 0 Answers