Hey! I’m building a Stamina Meter, that slowly decreases as the Stamina is depleted, and increases as the Stamina increases. I need this number to cap @ the values of “0” and “10”.
Using MathF.Clamp, I have managed to get the numbers to stop depleting @ 0, (after many iterations to get the system to work) but for some reason, it won’t stop it rising above 10.
I’ll post some of my code snippets below - If anyone could point out what I’ve done wrong!
Mathf Clamp & initial value of sprint
void Start
{
sprintCountdown = Mathf.Clamp(10f, 0f, 10f);
}
increasing & decreasing the value
if (sprint == true)
{
if (sprintCountdown > 0)
{
speed = 30;
sprintCountdown = decreaseSprint;
Debug.Log(sprintCountdown.ToString());
}
else
{
speed = 10;
}
}
else
{
speed = 10;
sprintCountdown = increaseSprint;
Debug.Log(sprintCountdown.ToString());
}
“Sprint” is Equals true, if Left Shift is being pressed.
To clarify, the meter works, the value decreases when shift is held, at the appropriate rate until it hits 0, and increases when shift isn’t held - but doesn’t stop at 10. can someone please help me?