using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Assets.Scripts.CharacterScripts{ public class HealthBarController : MonoBehaviour{ public Slider slider; // This moves the health bar image public Gradient gradient; // The gradient for the bar (ex: full health is green, low health is red) public Image healthFill; // The fill of the health bar (so the red color) public void SetMaxHealth(int health){ slider.maxValue = health; // Set the max value of the slider to the corresponding max health slider.value = health; // Set the current value of the health to max healthFill.color = gradient.Evaluate(1f); } public void SetHealth(int health){ slider.value = health; // Set the slider value to the current health healthFill.color = gradient.Evaluate(slider.normalizedValue); } } }