Counter.cs 494 B

123456789101112131415161718192021222324252627
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace LearnStorage
  6. {
  7. /// <summary>
  8. ///
  9. /// </summary>
  10. public class Counter : MonoBehaviour
  11. {
  12. public Text dt;
  13. public int time = 120;
  14. public float index = 1;
  15. private void Update()
  16. {
  17. if (Time.time >= index)
  18. {
  19. time--;
  20. dt.text = string.Format("{0:d2}:{1:d2}", time / 60, time % 60);
  21. index = Time.time + 1;
  22. }
  23. }
  24. }
  25. }