SWS-Smarta / project /Assets /Scripts /Game /DinoCountdownUI.cs
alfapro's picture
Clean deploy: Code only for SWS
defab59
Raw History Blame Contribute Delete
979 Bytes
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class DinoCountdownUI : MonoBehaviour
{
public TMP_Text countdownText;
public Text countdownTextLegacy;
public float hideDelay = 0.75f;
float goTime = -1f;
void Update()
{
DinoGameManager gm = DinoGameManager.Instance;
if (gm == null)
return;
if (gm.IsGameStarted)
{
if (goTime < 0f)
goTime = Time.time;
if (Time.time - goTime > hideDelay)
{
SetText("");
return;
}
SetText("GO!");
return;
}
float remaining = gm.GetCountdownRemaining();
int sec = Mathf.CeilToInt(remaining);
SetText(sec.ToString());
}
void SetText(string value)
{
if (countdownText != null) countdownText.text = value;
if (countdownTextLegacy != null) countdownTextLegacy.text = value;
}
}