Files

41 lines
1.1 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
using VRShopping.Player;
namespace VRShopping.UI
{
// 왼쪽 손목에 부착되는 허기 게이지 HUD.
// PlayerHunger.Instance에 자동 구독.
public class HungerHud : MonoBehaviour
{
[SerializeField] private Image _fillImage; // type=Filled 권장
[SerializeField] private TMP_Text _text; // 옵션, "80 / 100" 형식
[SerializeField] private PlayerHunger _bound;
private void Start()
{
_bound.OnHungerChanged += HandleChanged;
HandleChanged(_bound.Current, _bound.Max);
}
private void OnDestroy()
{
if (_bound != null)
{
_bound.OnHungerChanged -= HandleChanged;
_bound = null;
}
}
private void HandleChanged(float current, float max)
{
if (_fillImage != null && max > 0f)
_fillImage.fillAmount = Mathf.Clamp01(current / max);
if (_text != null)
_text.text = $"{Mathf.CeilToInt(current)} / {Mathf.CeilToInt(max)}";
}
}
}