Help with Mathf.Max please

I have an energy variable (float) that has a value of 100f.
I want to keep reducing this variable until it reaches 0f.
This this the script that I use:

energy = Mathf.Max(0f, energy - energyless);

I set the value of energyless to 0.001f and run the script.
From debug.log I can see the energy variable keep getting lower, but it never reached zero.
It seems to stop reducing at 0.001. Why is that?

where is that line of code being called from? what logic surrounds it?

1 Like

Thanks for your reply! It made me check my code again and while doing so I found the problem.
I forgot to remove another line that increase the energy variable.
So embarrassing … :sweat_smile:

:slight_smile: