maxhacker11

HealthBar.cs

Jul 27th, 2023
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | Source Code | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3.  
  4. public class HealthBar : MonoBehaviour
  5. {
  6.     public Slider slider;
  7.     public Gradient gradient;
  8.     public Image fill;
  9.  
  10.     public void SetMaxHealth(int health)
  11.     {
  12.         slider.maxValue = health;
  13.         slider.value = health;
  14.  
  15.         fill.color = gradient.Evaluate(1f);
  16.     }
  17.  
  18.     public void SetCurrentHealth(int health)
  19.     {
  20.         slider.value = health;
  21.  
  22.         fill.color = gradient.Evaluate(slider.normalizedValue);
  23.     }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment