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