I’m trying to make temporary movement boost while holding left shift. It works like stamina in Elder Scrolls games, you wait to get more stamina so you can boost yourself.
It seemed to work, but when the stamina fully drains out it doesn’t recharge.
Here’s my script
public float BoostTime = 2;
public float stamina;
public float speed;
void Start(){
stamina = BoostTime;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.LeftShift) && !Boosted)
{
Boosted = true;
}
if(Input.GetKeyUp(KeyCode.LeftShift) || stamina < 0)
{
stamina += Time.deltaTime;
Boosted = false;
if(stamina >= BoostTime)
{
stamina = BoostTime;
}
}
if(Boosted){
speed = 50f;
stamina -= Time.deltaTime;
}
if(!Boosted)
{
speed = 20f;
}```