fgm24/Assets/Scripts/UI/HealthDisplay.cs

32 lines
760 B
C#
Raw Normal View History

2024-02-03 01:14:34 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class HealthDisplay : MonoBehaviour
{
[SerializeField] string padding = "Health: ";
[SerializeField] TextMeshProUGUI healthText;
[SerializeField] HealthComponent healthComponent;
private void Start()
{
healthText.text = padding + healthComponent.currentHealth;
}
private void OnEnable()
{
healthComponent.OnHealthChange.AddListener(UpdateHealth);
}
private void OnDisable()
{
healthComponent.OnHealthChange.RemoveListener(UpdateHealth);
}
2024-02-04 01:25:59 +01:00
public void UpdateHealth(float prevHealth, float newHealth)
2024-02-03 01:14:34 +01:00
{
healthText.text = padding + healthComponent.currentHealth;
}
}