Files
2025TapTapGameJam/Assets/Script/Gameplay/UI/PlayerHpViewer.cs

35 lines
804 B
C#
Raw Normal View History

2025-10-15 21:31:13 +08:00
using System;
using Core;
using Gameplay.Player;
using UnityEngine;
using UnityEngine.UI;
namespace UI
{
public class PlayerHpViewer : UIBase
{
private PlayerController _playerController;
public Text hpText;
private void Awake()
2025-10-15 21:31:13 +08:00
{
ControllerLocator.Instance.TryGetWait<PlayerController>(OnGet);
2025-10-15 21:31:13 +08:00
}
private void OnGet(PlayerController playerController)
2025-10-15 21:31:13 +08:00
{
_playerController = playerController;
_playerController.OnHealthChanged += UpdateHpText;
2025-10-15 21:31:13 +08:00
}
private void UpdateHpText(int currentHealth)
2025-10-15 21:31:13 +08:00
{
hpText.text = "HP: " + currentHealth;
}
private void OnDestroy()
{
_playerController.OnHealthChanged -= UpdateHpText;
2025-10-15 21:31:13 +08:00
}
}
}