44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class GameStartCountdownUI : MonoBehaviour
|
|
{
|
|
private const string NumberPopup = "NumberPopup";
|
|
[SerializeField] private TextMeshProUGUI countdownText;
|
|
|
|
private Animator animator;
|
|
private int previousCountdownNumber;
|
|
|
|
private void Awake() => animator = GetComponent<Animator>();
|
|
|
|
private void Start()
|
|
{
|
|
KitchenGameManager.Instance.OnStateChanged += KitchenGameManager_OnStateChanged;
|
|
Hide();
|
|
}
|
|
|
|
private void KitchenGameManager_OnStateChanged(object sender, System.EventArgs e)
|
|
{
|
|
if (KitchenGameManager.Instance.IsCountToStartActive())
|
|
Show();
|
|
else
|
|
Hide();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
int countdownNumber = Mathf.CeilToInt(KitchenGameManager.Instance.CountdownToStartTimer);
|
|
countdownText.text = countdownNumber.ToString();
|
|
if (previousCountdownNumber != countdownNumber)
|
|
{
|
|
previousCountdownNumber = countdownNumber;
|
|
animator.SetTrigger(NumberPopup);
|
|
SoundManager.Instance.PlayCountdownSound();
|
|
}
|
|
}
|
|
|
|
private void Hide() => gameObject.SetActive(false);
|
|
|
|
private void Show() => gameObject.SetActive(true);
|
|
} |