Advertisement
evelynshilosky

ResourceHealthBar - Part 31

Feb 2nd, 2024
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class ResourceHealthBar : MonoBehaviour
  7. {
  8.  
  9.     private Slider slider;
  10.     private float currentHealth, maxHealth;
  11.  
  12.     public GameObject globalState;
  13.  
  14.     private void Awake()
  15.     {
  16.  
  17.         slider = GetComponent<Slider>();
  18.  
  19.     }
  20.  
  21.     private void Update()
  22.     {
  23.         currentHealth = globalState.GetComponent<GlobalState>().resourceHealth;
  24.         maxHealth = globalState.GetComponent<GlobalState>().resourceMaxHealth;
  25.  
  26.         float fillValue = currentHealth / maxHealth;
  27.         slider.value = fillValue;
  28.     }
  29.  
  30.  
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement