using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /* -------------------------------------- Project: Programing assessment Standard: 91906 (AS3.7) v.1 School: Tauranga Boys' College Author: Rauputu Noah Phizacklea Date: August 2024 Unity: 2021.3.18f --------------------------------------- */ public class HealthBar : MonoBehaviour { public Slider slider; // Reference to the UI Slider component public Gradient gradient; // Gradient for color transition based on health public Image fill; // Reference to the fill image of the Slider // Set the maximum health and initialize the health bar public void SetMaxHealth(int health) { slider.maxValue = health; // Set the maximum value of the slider slider.value = health; // Set the current value of the slider to max health fill.color = gradient.Evaluate(1f); // Set the fill color to the end of the gradient } // Update the health bar with current health value public void SetHealth(int health) { slider.value = health; // Update the slider value to current health fill.color = gradient.Evaluate(slider.normalizedValue); // Change fill color based on health percentage } }