using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CaloriesBar : MonoBehaviour { private Slider slider; public Text caloriesCounter; public GameObject playerState; private float currentCalories, maxCalories; // Start is called before the first frame update void Awake() { slider = GetComponent(); } // Update is called once per frame void Update() { currentCalories = playerState.GetComponent().currentCalories; maxCalories = playerState.GetComponent().maxCalories; float fillValue = currentCalories/maxCalories; slider.value = fillValue; caloriesCounter.text = currentCalories+"/"+maxCalories; } }