using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class HealthDisplay : MonoBehaviour { [SerializeField] string padding = "Health: "; [SerializeField] TextMeshProUGUI healthText; [SerializeField] HealthComponent healthComponent; private void Start() { healthText.text = padding + healthComponent.currentHealth; } private void OnEnable() { healthComponent.OnHealthChange.AddListener(UpdateHealth); } private void OnDisable() { healthComponent.OnHealthChange.RemoveListener(UpdateHealth); } public void UpdateHealth(int prevHealth, int newHealth) { healthText.text = padding + healthComponent.currentHealth; } }