I’m new to Unity and C# and trying to create a stamina bar for when player is sprinting.
public float sprintStaminaCurrent = 1.0f;
public float sprintStaminaDrainPerSecond = 0.1f;
public float sprintStaminaGainPerSecond = 0.02f;
//...
void Update()
{
if(sprintStatus == true){
sprintStaminaCurrent -= sprintStaminaDrainPerSecond * Time.deltaTime;
}else{
sprintStaminaCurrent += sprintStaminaGainPerSecond * Time.deltaTime;
}
sprintbar.Value = sprintStaminaCurrent;
}
This code is working but the stamina drain is too slow.
I was expecting consume 0.1 per second, I mean, 10 seconds to get empty.
It’s consuming something about 0.01 per second.
Am I doing something wrong with Time.deltaTime
?
1