- Home /
How Do I check if a Bool was True a few moments ago
I'm not sure if this can be done but lets say I have a bool I call:
public bool KITT_SaidThis = false;
I'm wondering is there a way to check if the bool just recently became "false"? In other words lets say it was true for a while but just now became "false" and you wanted to do something like an if check on this condition, something like:
if (KITT_SaidThis == false "just now or 2 seconds ago"){
Do something
}
Is this possible to do?
Answer by Metorphium · Nov 12, 2016 at 07:08 PM
You could set up a timer that starts when you call the bool true/false.
so it could be something like this :
float KITT_SaidThisTimer = 0f;
bool starttimer = false;
if (KITT_SaidThis == false)
starttimer = true;
if (starttimer == true)
KITT_SaidThisTimer += time.deltatime;
And then you can ask for the value of your timer in the next situation you need it. something like:
if (KITT_SaidThisTimer >= 5f && YOUR CONDITION) Dosomething;
That will ask if the Timer is bigger or equal to 5f
Ahh yes I see, I had thought of something like that but was a little fuzzy on quite how to go about it but yes this makes perfect sense thank you @$$anonymous$$etorphium :D
Answer by Kapel · Nov 12, 2016 at 08:43 PM
I just use print so i can see in console history if value was true/false. Very helpful because you can easy detect when it become true/false.
if (KITT_SaidThis == false ){
print("Value is true");
}
Your answer
Follow this Question
Related Questions
Could use some help on making my runaway/chase/follow/patrol script cooperate with each other 1 Answer
Scavenger Hunt List Bools Question 1 Answer
c# Ignoring conditional statement? 1 Answer
Check bool from another script and use in another script C# 3 Answers
Integer gets too many additions 2 Answers