using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class UnitWorldUI : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI actionPointsText;
[SerializeField] private Unit unit;
[SerializeField] private Image healthBarImage;
[SerializeField] private HealthSystem healthSystem;
private void Start() {
Unit.OnAnyActionPointsChanged += Unit_OnAnyActionPointsChanged;
healthSystem.OnDamaged += HealthSystem_OnDamaged;
UpdateActionPointsText();
UpdateHealthBar();
}
private void UpdateActionPointsText() {
// Debug.Log($"Setting to {unit.GetActionPoints().ToString()}");
actionPointsText.text = unit.GetActionPoints().ToString();
}
private void Unit_OnAnyActionPointsChanged(object sender, EventArgs empty) {
UpdateActionPointsText();
}
private void HealthSystem_OnDamaged(object sender, EventArgs empty) {
UpdateHealthBar();
}
private void UpdateHealthBar() {
// Debug.Log($"Setting to {healthSystem.GetHealthNormalized()}");
healthBarImage.fillAmount = healthSystem.GetHealthNormalized();
}
}