Hello, i would like some help, i have a Slider System for my health, I have 100hp and my Enemy dose 10hp, but i dont know how to get it so it just takes away the 10dmg from the 100 on the slider, right now it takes away 100% of the slider…
class CharacterStats : MonoBehaviour {
// HealthBar.
public Slider healthbar;
// Player Stats.
public int maxHealth = 100;
public int currentHealth { get; private set; }
public Stat damage;
public Stat armor;
void Awake()
{
currentHealth = maxHealth;
healthbar.value = CalculateHealth();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.H))
{
currentHealth += 15;
}
}
public void TakeDamage (int damage)
{
damage -= armor.GetValue();
damage = Mathf.Clamp(damage, 0, int.MaxValue);
currentHealth -= damage;
healthbar.value = CalculateHealth();
Debug.Log(transform.name + " takes " + damage + " damage.");
if (currentHealth <= 0)
{
Die();
}
}
float CalculateHealth()
{
return currentHealth / maxHealth;
}
public virtual void Die ()
{
// Die in some way
// This meathod is meant to be overwritten
Debug.Log(transform.name + " died.");
}
}