12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System;
- using TMPro;
- using UnityEngine;
- using Debug = System.Diagnostics.Debug;
- namespace Display
- {
- public class CountdownDisplay : InFrontOfCameraDisplay
- {
- public int countdown = 3;
- public TextMeshProUGUI countdownText;
- public delegate string CountdownDoneCallback();
- public CountdownDoneCallback OnCountdownDone { get; set; }
- private float lastTime;
- protected override void Start()
- {
- base.Start();
- lastTime = Time.time;
- }
- protected override void Update()
- {
- var t = Time.time;
- if (t - lastTime >= 1)
- {
- lastTime = t;
- countdown--;
- countdownText.text = $"{countdown}";
- if (countdown == 0)
- {
- countdownText.text = OnCountdownDone?.Invoke();
- Destroy(gameObject, 0.5f);
- }
- }
- base.Update();
- }
- }
- }
|