StartTimer.cs 714 B

123456789101112131415161718192021222324252627282930
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using DG.Tweening;
  6. public class StartTimer : MonoBehaviour
  7. {
  8. int time = 3;
  9. void Start()
  10. {
  11. this.ChangeTime();
  12. }
  13. void ChangeTime()
  14. {
  15. this.transform.localScale = new Vector3(1, 1, 1);
  16. this.GetComponent<Text>().text = this.time > 0 ? this.time.ToString() : "开始";
  17. this.transform.DOScale(new Vector3(0.75f, 0.75f, 1), 0.8f).OnComplete(delegate() {
  18. this.time--;
  19. if (this.time >= 0)
  20. {
  21. this.ChangeTime();
  22. } else {
  23. Destroy(this.gameObject);
  24. }
  25. });
  26. }
  27. }