1 using System; 2 using UnityEngine; 3 using System.Collections; 4 5 public class TimeCountdown : MonoBehaviour 6 { 7 8 //之前的一个时间点 9 public long startTime = 1379342120; 10 //限定时间秒 11 private long fixedTime = 200000; 12 private long nowTime; 13 14 15 16 17 // Use this for initialization 18 void Start() 19 { 20 nowTime = (System.DateTime.Now.Ticks - System.DateTime.Parse("1970-01-01").Ticks) / 10000000; 21 if (nowTime - startTime >= fixedTime) 22 { 23 Debug.Log("倒计时结束"); 24 } 25 else 26 { 27 InvokeRepeating("CountDown", 0, 1); 28 } 29 } 30 31 // Update is called once per frame 32 void Update() 33 { 34 35 } 36 37 void CountDown() 38 { 39 fixedTime -= 1; 40 gameObject.GetComponent<UILabel>().text = (fixedTime / (60 * 60 * 24)).ToString() + "天" 41 + ((fixedTime/60 - fixedTime / (60 * 60 * 24)*24*60)/60).ToString() + "小时" 42 + ((fixedTime / 60) % 60).ToString() + "分" 43 + (fixedTime % 60).ToString() + "秒"; 44 } 45 }