using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnergyText : MonoBehaviour { private EnergyController _energyController; private TMPro.TextMeshProUGUI _text; private void Awake() { _energyController = FindObjectOfType(); _text = GetComponent(); } private void OnEnable() { _energyController.OnEnergyChange += UpdateText; } private void OnDisable() { _energyController.OnEnergyChange -= UpdateText; } private void UpdateText(float energy) { _text.SetText(energy.ToString()); } }