2026-01-13 21:40:48 +00:00
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class HUD_HP : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public TextMeshProUGUI t_hp;
|
|
|
|
|
|
|
|
|
|
protected Camera m_Camera;
|
|
|
|
|
protected Transform m_Actor;
|
|
|
|
|
RectTransform m_RectTransform;
|
|
|
|
|
RectTransform CanvasRect;
|
|
|
|
|
public Vector2 offset = new Vector2(-5f, 0f);
|
|
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
|
{
|
|
|
|
|
if (m_Camera == null) m_Camera = Camera.main;
|
|
|
|
|
if (CanvasRect == null) CanvasRect = GameUI.Ins.GetComponent<RectTransform>();
|
|
|
|
|
m_RectTransform = GetComponent<RectTransform>();
|
|
|
|
|
transform.localScale = Vector3.one * 0.5f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Set(Transform tf, int hp)
|
|
|
|
|
{
|
|
|
|
|
Set(hp);
|
|
|
|
|
Init();
|
|
|
|
|
m_Actor = tf;
|
|
|
|
|
t_hp.text = hp.ToString();
|
|
|
|
|
}
|
|
|
|
|
public void Set(int hp)
|
|
|
|
|
{
|
|
|
|
|
t_hp.text = hp.ToString();
|
2026-01-16 04:53:55 +00:00
|
|
|
//gameObject.SetActive(hp > 0);
|
|
|
|
|
gameObject.SetActive(false);
|
2026-01-13 21:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
if (m_Camera == null) m_Camera = Camera.main;
|
|
|
|
|
if (m_Actor)
|
|
|
|
|
{
|
|
|
|
|
Vector2 ViewportPosition = m_Camera.WorldToViewportPoint(m_Actor.position);
|
|
|
|
|
Vector2 WorldObject_ScreenPosition = new Vector2((ViewportPosition.x * CanvasRect.sizeDelta.x) - (CanvasRect.sizeDelta.x * 0.5f), (ViewportPosition.y * CanvasRect.sizeDelta.y) - (CanvasRect.sizeDelta.y * 0.5f) - 15f);
|
|
|
|
|
m_RectTransform.anchoredPosition = WorldObject_ScreenPosition + offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|