Files
Shopping_UnityVR/Assets/02_Scripts/UI/GameTimerHud.cs

35 lines
823 B
C#

using TMPro;
using UnityEngine;
namespace VRShopping.UI
{
public class GameTimerHud : MonoBehaviour
{
[SerializeField] private GameTimer _timer;
[SerializeField] private TMP_Text _text;
private void OnEnable()
{
if (_timer == null) return;
_timer.OnTick += HandleTick;
HandleTick(_timer.Remaining);
}
private void OnDisable()
{
if (_timer == null) return;
_timer.OnTick -= HandleTick;
}
private void HandleTick(float remaining)
{
if (_text == null) return;
int total = Mathf.CeilToInt(remaining);
int minutes = total / 60;
int seconds = total % 60;
_text.text = $"{minutes:00}:{seconds:00}";
}
}
}