Posted earlier trying to fudge a stamina bar as everything I tried online is just too far off what I have to work ( and " yes" I tried VERY hard to adapt). SO my fudge is that since the left shift is the sprint, I have a script that brings down my stamina bar. I had to use “GetKey” as opposed to “GetKeyDown” because GetKeyDown only moved the bar one increment where GetKey steadily moves the bar as long as it is pressed. My problem is that I can’t figure out how to reset the stamina bar. I was hoping to use “GetKeyUp” with the same key so when I release the left shift and stop running the bar would slowly replenish. But as you can see there is a conflict as I can only do the GetKeyUp once and it only replenishes one increment ( same issue I had with depleting the stamina bar). How can I reset the Stamina bar so in 5 seconds after I do “GetKeyUp” the bar will be full again? I know I could just set the amount to 100 and fill it up again but there needs to be some down time after a sprint
This is the code I have for the bar
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class newStaminaTry: MonoBehaviour
{
public float startingStamina = 100;
public float currentStamina;
public Slider StaminaSlider;
void Awake ()
{
currentStamina = startingStamina;
}
void Update ()
{
if (Input.GetKey(KeyCode.LeftShift))
{
currentStamina -= .5f;
StaminaSlider.value = currentStamina;
}
if (Input.GetKeyUp(KeyCode.LeftShift))
currentStamina += 10f;
StaminaSlider.value = currentStamina;
}
}