- Home /
Reducing an integer by X per second
I am trying to make a simple stamina bar. So when you are holding left shift to sprint the stamina which has a start value of 100 is decreasing by 5 per second.
if(Input.GetKeyDown("left shift"))
{
Running = true;
staticVAR.STAMINA -= 10;
}
As you can see here it is currently just reducing the value by 10 each time the key is pressed, but I would like it to decrease as the key is held down. Can anyone help me out with this? :)
Comment
Answer by tanoshimi · Jun 07, 2015 at 12:53 PM
To make any rate "per second", multiply by Time.deltaTime:
staticVAR.STAMINA -= 5f * Time.deltaTime;
Your answer
Follow this Question
Related Questions
How to sprint and have a stamina bar? 0 Answers
Movement script with a draining stamina bar 1 Answer
sprint and stamina problems 0 Answers