I have this simple sprinting script and basically the problem is when I hold shift to sprint it goes down but not continuously. The only way to get it down to 0 is to spam the sprint key over and over again. If I hold it down he continues to sprint but my stamina regenerates back to full. Any idea why it won’t just continuously drain while holding sprint down?
if (Input.GetKeyDown(KeyCode.LeftShift))
{
if (Stamina >= StaminaDecreasePerFrame)
{
isSprinting = true;
speed = sprintSpeed;
Stamina = Mathf.Clamp(Stamina - StaminaDecreasePerFrame, 0.0f, MaxStamina);
StaminaRegenTimer = 0.0f;
}
}
else if (Stamina < MaxStamina)
{
if (StaminaRegenTimer >= StaminaTimeToRegen)
{
Stamina = Mathf.Clamp(Stamina + StaminaIncreasePerFrame, 0.0f, MaxStamina);
}
StaminaRegenTimer += Time.deltaTime;
}