Health Slider..HELP SOLVED

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.");
    }

}

You’re dividing an integer by another integer here:

float CalculateHealth()
{
    return currentHealth / maxHealth;
}

The result is always an integer before it’ll be implicity converted to a float, so it cuts off any fraction that you’d get in a floating point calculation.

You want to turn either one of them (or both) into floats or do an explicit cast, for example

float CalculateHealth()
{
    return currentHealth / (float)maxHealth;
}

You could as well set the slider’s max value to be equal to the maxHealth value and assign the currentHealth to it whenever it changes.
However, that might introduce bugs if you allow changes to the maxHealth after initialization and forget to update the slider’s max value accordingly via code.

aah tnx man :smile:D it worked