Spaces:
Sleeping
Sleeping
File size: 979 Bytes
defab59 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 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;
}
}
|