Advertisement
evelynshilosky

HydrationBar - Part 31

Feb 1st, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class HydrationBar : MonoBehaviour
  7. {
  8.  
  9.     private Slider slider;
  10.     public Text hydrationCounter;
  11.  
  12.     public GameObject playerState;
  13.  
  14.     private float currentHydration, maxHydration;
  15.  
  16.     void Awake()
  17.     {
  18.         slider = GetComponent<Slider>();
  19.     }
  20.  
  21.  
  22.     void Update()
  23.     {
  24.         currentHydration = playerState.GetComponent<PlayerState>().currentHydrationPercent;
  25.         maxHydration = playerState.GetComponent<PlayerState>().maxHydrationPercent;
  26.  
  27.         float fillValue = currentHydration / maxHydration;
  28.         slider.value = fillValue;
  29.  
  30.         hydrationCounter.text = currentHydration + "%";
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement