2026-04-28 왼쪽 손목에 포만감 배치
This commit is contained in:
40
Assets/02_Scripts/UI/HungerHud.cs
Normal file
40
Assets/02_Scripts/UI/HungerHud.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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)}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user