Files
BABA_YAGA/Assets/Scripts/UI/MazeUI.cs

52 lines
1.4 KiB
C#

using UnityEngine;
using TMPro;
using System.Collections;
namespace OnlyScove.Scripts.UI
{
public class MazeUI : MonoBehaviour
{
public static MazeUI Instance { get; private set; }
[Header("References")]
[SerializeField] private GameObject winPanel;
[SerializeField] private TextMeshProUGUI winMessageText;
[SerializeField] private TextMeshProUGUI timerText;
private void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
if (winPanel != null) winPanel.SetActive(false);
}
public void UpdateTimer(float time)
{
if (timerText != null)
timerText.text = $"Time: {time:F2}s";
}
public void ShowWinMessage(string playerName, float time)
{
if (winPanel == null) return;
winPanel.SetActive(true);
if (winMessageText != null)
{
winMessageText.text = $"<color=yellow>{playerName}</color>\nREACHED THE GOAL!\n<size=80%>IN {time:F2} SECONDS</size>";
}
// Tự động ẩn sau 5 giây
StopAllCoroutines();
StartCoroutine(HideWinPanel());
}
private IEnumerator HideWinPanel()
{
yield return new WaitForSeconds(5f);
winPanel.SetActive(false);
}
}
}