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

Unity3D倒计时两种方法

时间:2017-08-11 17:24:47      阅读:496      评论:0      收藏:0      [点我收藏+]

标签:else   raw   min   last   text   ndpi   unity3d   dpi   var   


一.简单的倒计时:
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倒计时两种方法

标签:else   raw   min   last   text   ndpi   unity3d   dpi   var   

原文地址:http://www.cnblogs.com/wangrongjie/p/7346888.html

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