#sure
1 messages · Page 1 of 1 (latest)
say it's been 10 seconds since your game started.
Thirst = Time.time * 10; // Thirst gets set to 100
if (Thirst >= 100f)
{
animator.Play("Drinking");
Thirst -= 100f;
}
``` This condition for this if statement is true
Thirst, in the same frame that it is being set to 100, being set back to 0
Thirst_Text.text = "Thirst " + Thirst.ToString();
``` Thirst was set to 0 directly before this line is executed
this should print
Thirst 0
The logic for this frame has finished executing
next frame, Thirst is being set to Time.time * 10, and Time.time was already 10 seconds last frame, so now it'll be (10 + Time.deltaTime) * 10 I believe.
so Thirst is over 100
Thirst = Mathf.Clamp(Thirst, 0, 100);
``` Thirst is set to 100 in this line
and from here on, the logic is executed in the exact same way as last frame @polar current
animator.Play("Drinking"); will be called every frame after 10 seconds (since the game started) has elapsed
and you'll always have the value 0 printed to the console
and Thirst_Text.text will be set to
Thirst 0
others have said it elsewhere, but here's some explicit code:
the way to get your intended effect is to replace
Thirst = Time.time * 10;
Thirst = Mathf.Clamp(Thirst, 0, 100);
``` with
```cs
Thirst += Time.deltaTime * 10;
bye now. sleep time