Reducing an int "while" a bool is true
Greetings community! I am a new to Unity as of March. Here is the breakdown of my question, my object has a script attached, with a int value for mood. I want the mood to be reduced by 10 while the bool "exhausted" == true. I feel I would need this check in update but.... If I put this in the update frame as so:
void Update()
{
if (exhausted ==true)
{
mood -=10;
}
}
the problem of course is that this will reduce mood by 10 every frame while exhausted is true. Any advice much appreciated!
Answer by Zymurer · Jan 08, 2021 at 10:51 AM
I don't wanna look smarty but let me correct. This language is C#, unity dosen't use C++.
About the problem the solution is simple, just set your exhausted to false again:
void Update()
{
if (exhausted ==true)
{
mood -=10;
exhausted = false;
}
}
Hope that helps.
Thank you for your response. I will probably mix up my C's for a while lol. That would indeed work, but I need to add more detail. Certain INT's (energy specifically) are checked for in the update which activate the exhausted bool as true. Since this is checked in update it would simply reactivate the exhaustion the following frame as that energy has unlikely changed. Exhaustion, also has a few other effects while active, otherwise I would get rid of it all together and just check the energy level for the mood adjustment.
Your answer
Follow this Question
Related Questions
Timer onTriggerEnter doesn't launch 0 Answers
C# update code runs twice ? 1 Answer
AudioSource in Update 1 Answer
Boolean not functioning as intended. 1 Answer
My Animator and C-Sharp Bools won't work together? 0 Answers