So my question is how do I slow down an int so if im taking away or adding to somethig… because when i run my stamina goes ywa to fast cuase the get key stacks same with taking damage or adding health. The health is still being worked on thats why im using key codes.
public void Update()
{
if (Input.GetKey(KeyCode.P))
{
TakeDamage(2);
}
if (Input.GetKey(KeyCode.L))
{
AddHealth(50);
}
}
public void TakeDamage(int damage)
{
if(currentHealth - damage >= 0)
{
currentHealth -= damage;
healthBar.value = currentHealth;
}
}
public void AddHealth(int heal)
{
if(currentHealth + heal >= 0)
{
currentHealth += heal;
healthBar.value = currentHealth;
}
}
// Stamina script
public void UseStamina( int amount)
{
if(currentStamina - amount >= 0)
{
currentStamina -= amount;
staminaBar.value = currentStamina;
if(regen != null)
{
StopCoroutine(regen);
}
regen = StartCoroutine(RegenStamina());
}
}