31 lines
664 B
C#
31 lines
664 B
C#
|
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());
|
||
|
}
|
||
|
}
|