KitchenChaos/Assets/Scripts/UI/GameStartCountdownUI.cs

45 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 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 KitchenGameManager_OnStateChanged(object sender, EventArgs e) {
if (KitchenGameManager.Instance.IsCountToStartActive())
Show();
else
Hide();
}
private void Hide() {
gameObject.SetActive(false);
}
private void Show() {
gameObject.SetActive(true);
}
}