Unity3D C# 简单的倒计时
2016-06-30 17:23
686 查看
using System;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TimeCountdown : MonoBehaviour
{
//之前的一个时间点
public long startTime = 1435870304;
//限定时间秒
private long fixedTime = 200000;
private long nowTime;
bool isOver = false;
// Use this for initialization
void Start()
{
nowTime = (System.DateTime.Now.Ticks - System.DateTime.Parse("1970-01-01").Ticks) / 10000000;
Debug.Log(nowTime.ToString());
InvokeRepeating("CountDown", 0, 1);
}
// Update is called once per frame
void Update()
{
if (!isOver && nowTime - startTime >= fixedTime)
{
Debug.Log("倒计时结束");
isOver = true;
}
}
void CountDown()
{
fixedTime -= 1;
gameObject.GetComponent<Text>().text = (fixedTime / (60 * 60 * 24)).ToString() + "天"
+ ((fixedTime / 60 - fixedTime / (60 * 60 * 24) * 24 * 60) / 60).ToString() + "小时"
+ ((fixedTime / 60) % 60).ToString() + "分"
+ (fixedTime % 60).ToString() + "秒";
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TimeCountdown : MonoBehaviour
{
//之前的一个时间点
public long startTime = 1435870304;
//限定时间秒
private long fixedTime = 200000;
private long nowTime;
bool isOver = false;
// Use this for initialization
void Start()
{
nowTime = (System.DateTime.Now.Ticks - System.DateTime.Parse("1970-01-01").Ticks) / 10000000;
Debug.Log(nowTime.ToString());
InvokeRepeating("CountDown", 0, 1);
}
// Update is called once per frame
void Update()
{
if (!isOver && nowTime - startTime >= fixedTime)
{
Debug.Log("倒计时结束");
isOver = true;
}
}
void CountDown()
{
fixedTime -= 1;
gameObject.GetComponent<Text>().text = (fixedTime / (60 * 60 * 24)).ToString() + "天"
+ ((fixedTime / 60 - fixedTime / (60 * 60 * 24) * 24 * 60) / 60).ToString() + "小时"
+ ((fixedTime / 60) % 60).ToString() + "分"
+ (fixedTime % 60).ToString() + "秒";
}
}
相关文章推荐
- Unity3D-扩展编辑器
- Unity 3D-- 摄像机Clear Flags和Culling Mask属性用途详解
- 关于Unity
- android引入unity-classes.jar之后进行混淆的问题解决
- 【Unity Shaders】学习笔记——SurfaceShader(八)生成立方图
- Unity 中Android SDK配置
- Unity3D UGUI之自制定时器(二)
- Unity3D游戏开发之SQLite让数据库开发更简单
- unity3d对象添加了碰撞体以后OnMouseDown事件
- 在unity使用ScriptableObject制作配置文件
- Unity插件 - MeshEditor(三) 面片破碎&网格破碎
- Unity插件 - MeshEditor(三) 面片破碎&网格破碎
- U3D学习日记一:坦克大战,初步建立场景
- unity学习笔记
- Unity3D 5.3 新版AssetBundle使用方案及策略
- 第一个工程2,-写个简单的测试程序
- unity 5.3.1播放视频文件
- Unity3D研究院之两种方式播放游戏视频(二十五)
- Unity应用的iOS热更新
- 深入理解IOC模式及Unity框架