3DSurvivalGame / Assets /Scripts /CaloriesBar.cs
doc2txt's picture
1
3497d64
raw
history blame contribute delete
No virus
815 Bytes
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<Slider>();
}
// Update is called once per frame
void Update()
{
currentCalories = playerState.GetComponent<PlayerState>().currentCalories;
maxCalories = playerState.GetComponent<PlayerState>().maxCalories;
float fillValue = currentCalories/maxCalories;
slider.value = fillValue;
caloriesCounter.text = currentCalories+"/"+maxCalories;
}
}