32 lines
760 B
C#
32 lines
760 B
C#
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);
|
|
}
|
|
|
|
public void UpdateHealth(float prevHealth, float newHealth)
|
|
{
|
|
healthText.text = padding + healthComponent.currentHealth;
|
|
}
|
|
}
|