码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D 简单的倒计时

时间:2014-12-13 06:14:07      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

 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 }

bubuko.com,布布扣

Unity3D 简单的倒计时

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/dabiaoge/p/4160882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!