using UnityEngine; using UnityEngine.UI; public class HealthBar : MonoBehaviour { public PlayerController playerController; public Slider healthBar; public float maxHealth; private void Start() { playerController = GameObject.Find("Player").GetComponent(); healthBar = GameObject.Find("HealthBar").GetComponent(); if (healthBar) { healthBar.maxValue = maxHealth; } } public void Update() { if(playerController && playerController.bHasBeenDamaged) { healthBar.value = playerController.health; } } }