Files
2025-12-02 14:28:00 +07:00

42 lines
1.2 KiB
C#

using System;
using CSNetwork.GPDataType;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster.PerfectWorld.Scripts.UI
{
public class UIPlayer : MonoBehaviour
{
public Image healthImage;
// public TextMeshProUGUI healthText;
[Header("DEBUG")]
[SerializeField] private CECPlayer hostplayer;
private void Start()
{
hostplayer = GetComponentInParent<CECPlayer>();
if (hostplayer == null)
{
Debug.LogError("Host player not found");
return;
}
EventBus.SubscribeChannel<cmd_self_info_00>(hostplayer.m_PlayerInfo.cid,UpdateHostPlayerInfoUI);
}
private void OnDestroy()
{
if (hostplayer == null)
{
Debug.LogError("Host player not found");
return;
}
EventBus.UnsubscribeChannel<cmd_self_info_00>(hostplayer.m_PlayerInfo.cid,UpdateHostPlayerInfoUI);
}
private void UpdateHostPlayerInfoUI(cmd_self_info_00 obj)
{
//healthText.text = $"{obj.iHP}/{obj.iMaxHP}";
healthImage.fillAmount = (float)obj.iHP / obj.iMaxHP;
}
}
}