rabidus-test/Assets/EnergyText.cs

31 lines
664 B
C#
Raw Normal View History

2023-07-28 11:48:57 +03:00
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<EnergyController>();
_text = GetComponent<TMPro.TextMeshProUGUI>();
}
private void OnEnable()
{
_energyController.OnEnergyChange += UpdateText;
}
private void OnDisable()
{
_energyController.OnEnergyChange -= UpdateText;
}
private void UpdateText(float energy)
{
_text.SetText(energy.ToString());
}
}