35 lines
810 B
C#
35 lines
810 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class EnergyUI : MonoBehaviour
|
|
{
|
|
public Text text;
|
|
|
|
private EnergyPool pool;
|
|
|
|
public void Init(EnergyPool pool) {
|
|
this.pool = pool;
|
|
pool.OnEnergyChanged += this.NotifyEnergyChanged;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
Render();
|
|
}
|
|
|
|
private void Render()
|
|
{
|
|
string currentEnergyString = "" + this.pool.Energy;
|
|
if (this.pool.Energy == 0) {
|
|
currentEnergyString = "<color=red>" + currentEnergyString + "</color>";
|
|
}
|
|
text.text = "Energy: " + currentEnergyString + " / " + this.pool.MaxEnergy;
|
|
}
|
|
|
|
public void NotifyEnergyChanged() {
|
|
Render();
|
|
}
|
|
}
|