KitchenChaos/Assets/Scripts/UI/GamePlayingClockUI.cs

33 lines
930 B
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class GamePlayingClockUI : MonoBehaviour {
[SerializeField] private Image timerImage;
[SerializeField] private TextMeshProUGUI timerText;
public static GamePlayingClockUI Instance { get; private set; }
private void Awake() {
Instance = this;
}
private void Start() {
Show();
}
private void Update() {
float playingTimeNormalized = KitchenGameManager.Instance.GetGamePlayingTimerNormalized();
timerImage.fillAmount = playingTimeNormalized;
timerImage.color = Color.Lerp(Color.green, Color.red, playingTimeNormalized);
int timeLeft = Mathf.CeilToInt(KitchenGameManager.Instance.GamePlayingTimer);
timerText.text = timeLeft.ToString();
}
public void Hide() {
gameObject.SetActive(false);
}
public void Show() {
gameObject.SetActive(true);
}
}