Stamina Consuption

Hey I am pretty new to scripting and I have seen similar questions here before, although I cant seem to find a solution to the problem I have.
Basically, I have two scripts one of them is In my Character and one of them is in my Slider (Stamina Bar)

The slider is my stamina and it can regen and deplete. (Stamina Script)
Though when I press shift suddenly all my stamina is gone (Character script)

The stamina script is fine, the problem is in the character.
Why is this suddenly depleting ALL my stamina? I want it to deplete progressively when holding down shift.
This is probably very simple but for an beginner this can be very time consuming. XD

 void Update()
    if (Input.GetKey(KeyCode.LeftShift))

Remember that your game runs at X frames per second - usually at least 30. That means that each frame takes about 1 / 30 of a second (or ~0.033 seconds).
The Update function is called for each and every one of these frames, or at least 30 times a second, and each time it’s called you’re reducing the stamina by 15 points out of the total.

Even if you only press the button for 1/4 of a second, you’re effectively calling the Update function about
30/4 times, or ~7-8 times. Multiply that by 15, and you get a stamina use of ~112 on average.

This is where Time.deltaTime comes in handy. This value is set to the time since the last frame was processed, or ~ 1/ 30 (or whatever frame rate your game is running at).
What this means for you, is that you can “fix” the rate of stamina use from per-frame basis, to per-second basis.

If you multiply the rate of stamina use by Time.deltaTime, you’ll get a gradual reduction of 15 points per second the button is held. From here you can tweak the stamina use value, add other multipliers, etc. to achieve the mechanics and feel you’re going for.

Example code:

class StaminaUser : MonoBehaviour
	// this value will show in the Inspector for easy editing, but default to 15
	public float StaminaUseRate = 15;

	private void Update()
		if (Input.GetKey(KeyCode.LeftShift))
			StaminaBar.instance.UseStamina(StaminaUseRate * Time.deltaTime); // multiply by Time.deltaTime to convert to per-second rate