Unity3D倒计时两种方法

Posted 不离不弃

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3D倒计时两种方法相关的知识,希望对你有一定的参考价值。


一.简单的倒计时:
var time_:int;
function Update()
{
time_=100-Time.time;
print(time_.ToString());
}
二.Unity3D GUI 时钟脚本:
var Tu1 : Texture2D;
var Time1 : float = 0;
function FixedUpdate () {
Time1 += Time.deltaTime;
}
function OnGUI () {
GUI.Label(Rect(250,170,161,62),getTime(Time1));
GUIUtility.RotateAroundPivot (6*Time1, Vector2(103, 200));
GUI.DrawTexture(Rect(100,100,6,100),Tu1);//秒针
GUIUtility.RotateAroundPivot (-6*Time1, Vector2(103, 200));
GUIUtility.RotateAroundPivot (0.1*Time1, Vector2(103, 200));
GUI.DrawTexture(Rect(100,120,6,80),Tu1);//分针
GUIUtility.RotateAroundPivot (-0.1*Time1, Vector2(103, 200));
GUIUtility.RotateAroundPivot (0.1/60*Time1, Vector2(103, 200));
GUI.DrawTexture(Rect(100,140,6,60),Tu1);//时针
GUIUtility.RotateAroundPivot (-0.1/60*Time1, Vector2(103, 200));
}
function getTime(time : float) : String{
if(time<0){
return "00:00:00";
}
var lastTime : String = "";
var hour = Mathf.FloorToInt(time/3600%24);
if(hour/10 >=1){
lastTime+="" + hour;
}else{
lastTime +="0" + hour;
}
var minute = Mathf.FloorToInt(time/60%60);
if(minute/10 >=1){
lastTime+=":" + minute;
}else{
lastTime +=":0" + minute;
}
var second = Mathf.FloorToInt(time%60);
if(second/10 >=1){
lastTime+=":" + second;
}else{
lastTime +=":0" + second;
}
return lastTime;
}



以上是关于Unity3D倒计时两种方法的主要内容,如果未能解决你的问题,请参考以下文章

前端开发——两种定时器

一起Talk Android吧(第三百八十九回:介绍两种实现倒计时的方法)

一起Talk Android吧(第三百八十九回:介绍两种实现倒计时的方法)

获取验证码显示的两种简单实现,交互绝非偶然~

Unity3D中三种调用其他脚本函数的方法

Unity3D占用内存太大的解决方法