35 lines
804 B
C#
35 lines
804 B
C#
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()
|
|
{
|
|
ControllerLocator.Instance.TryGetWait<PlayerController>(OnGet);
|
|
}
|
|
|
|
private void OnGet(PlayerController playerController)
|
|
{
|
|
_playerController = playerController;
|
|
_playerController.OnHealthChanged += UpdateHpText;
|
|
}
|
|
|
|
private void UpdateHpText(int currentHealth)
|
|
{
|
|
hpText.text = "HP: " + currentHealth;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_playerController.OnHealthChanged -= UpdateHpText;
|
|
}
|
|
}
|
|
} |