Advertisement
evelynshilosky

CaloriesBar - Part 10

Jun 3rd, 2024
83
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 CaloriesBar : MonoBehaviour
  7. {
  8.  
  9.     private Slider slider;
  10.     public Text caloriesCounter;
  11.  
  12.     public GameObject playerState;
  13.  
  14.     private float currentCalories, maxCalories;
  15.  
  16.     void Awake()
  17.     {
  18.         slider = GetComponent<Slider>();
  19.     }
  20.  
  21.  
  22.     void Update()
  23.     {
  24.         currentCalories = playerState.GetComponent<PlayerState>().currentCalories;
  25.         maxCalories = playerState.GetComponent<PlayerState>().maxCalories;
  26.  
  27.         float fillValue = currentCalories / maxCalories; // 100/100
  28.         slider.value = fillValue;
  29.  
  30.         caloriesCounter.text = currentCalories + "/" + maxCalories;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement