so i made a script about a slider which i want only to decrease when a button is pressed and stop when the button is not being pressed but when i tried it and i have a problem when i press it and hold it it only decreases by 15 i want it to decrease slowly even if the button is pressed on
pls help
I used this code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class StaminaBar : MonoBehaviour
{
public Slider staminaBar;
private int currentStamina;
private int maxStamina = 100;
public static StaminaBar instance;
// Start is called before the first frame update
private void Awake()
{
instance = this;
}
void Start()
{
currentStamina = maxStamina;
staminaBar.maxValue = maxStamina;
staminaBar.value = maxStamina;
}
public void useStamina(int amount)
{
if(currentStamina - amount >= 0)
{
currentStamina -= amount;
staminaBar.value = currentStamina;
}
else
{
Debug.Log("Not Enough Stamina");
}
}
if(Input.GetKeyDown(KeyCode.LeftShift))
{
StaminaBar.instance.useStamina(15);
}
}