- Home /
Question by
oliver-jones · Apr 04, 2011 at 04:39 PM ·
functionbooleanifseconds
If function Question
Hello,
Is there a way to say:
if(boolean has == false for 2 seconds){
//do something
}
Not sure if there is a simple solution, but any help would be appreciated. (This is wihtin an Update Function)
Thanks
Comment
Best Answer
Answer by Bryan 4 · Apr 04, 2011 at 04:41 PM
Are you trying to determine if a boolean is false for two seconds? If so, just create a timer within your script for holding how long it is false for.
if(has == false) (add delta time to timer) else (has ==true) reset timer to 0.
if(timer > 2 seconds) (do stuff)
for c# it would be like..
//add this to the script variables. float timer =0.0f;
if(has == false) { timer += Time.deltatime; } else { timer = 0.0f; }
if(timer > 2.0f) { //has was false for 2+ seconds }