Question by
tguedes2021 · Jan 12 at 11:00 AM ·
scripting problemprogrammingscripting beginner
im trying to make it so when the Stamina reaches below 5, then the shift key will be disabled and when it is above 5, it will enable the shift key.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class StaminaBar : MonoBehaviour {
public Slider StaminaSider;
public float Stamina;
float maxStamina = 100;
public bool EnableDisable = false;
// Start is called before the first frame update
void Start()
{
Stamina = maxStamina;
}
// Update is called once per frame
void Update()
{
StaminaSider.value = Stamina;
Stamina = Stamina + 10f * Time.deltaTime;
if (Stamina < 5)
{
EnableDisable = true;
}
if (Stamina > 5)
{
EnableDisable = false;
}
if (Input.GetKey(KeyCode.LeftShift) && EnableDisable == false)
{
Stamina -= 25f * Time.deltaTime;
}
}
}
Comment