using TMPro; using UnityEngine; public class GameHUD : MonoBehaviour { [SerializeField] private Health playerHealth; [SerializeField] private GameManager gameManager; [SerializeField] private TMP_Text hitPointText; [SerializeField] private TMP_Text timeText; [SerializeField] private TMP_Text stateText; private void OnEnable() { if (playerHealth != null) { playerHealth.Changed += SetHitPoint; SetHitPoint(playerHealth.CurrentHitPoint, playerHealth.MaxHitPoint); } if (gameManager != null) { gameManager.TimeChanged += SetTime; gameManager.StateChanged += SetState; SetTime(gameManager.RemainingTime); SetState(gameManager.State); } } private void OnDisable() { if (playerHealth != null) { playerHealth.Changed -= SetHitPoint; } if (gameManager != null) { gameManager.TimeChanged -= SetTime; gameManager.StateChanged -= SetState; } } private void SetHitPoint(int current, int max) { if (hitPointText != null) { hitPointText.text = $"HP: {current} / {max}"; } } private void SetTime(float remainingTime) { if (timeText != null) { timeText.text = $"TIME: {Mathf.CeilToInt(remainingTime)}"; } } private void SetState(GameState state) { if (stateText == null) { return; } stateText.text = state switch { GameState.Clear => "CLEAR", GameState.GameOver => "GAME OVER", _ => string.Empty }; } }