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?