Health Bar doesnt fit my float var

im still beginner in Unity…

so i have this script to set my Health Bar but it doesnt fit with float var. what logic should i use to this? ( i know i should change " healthBar.SetMaxHealth(); " logic but i dont know what code to use for it. Any suggestion?

using UnityEngine;

public class Enemy : MonoBehaviour
{
    public float startHealth = 50f;
    private float health;

    [Header("Unity Stuff")]
    public HealthBarScript healthBar;

    private void Start()
    {
        health = startHealth;
        healthBar.SetMaxHealth(startHealth);
    }

    public void TakeDamage (float amount)
    {
        health -= amount;
        if (health <= 0f)
        {
            Die();
        }
        healthBar.SetHealth(health);
  
    }

    void Die()
    {
        Destroy(gameObject);
    }
}

When I implement a health bar, I use a slider component which has a build in slide between a min and max value. You can set these in the inspector like 0 min value and 100 max value for example.

There are a lot of tutorials on this on youtube.

Incase you want to normalize a value to be between 0-1 you can scale the value.

To scale, you need to divide your raw value by the total range, and account for an offset if min != 0. For a range of (min, max):

 scaledValue = (rawValue - min) / (max - min);

For the common case where min == 0:

 scaledValue = rawValue / max;