2017年1月3号,周二,晴。
//设置时间
float tempTime = 5;
void OnGUI(){
//设置显示
GUI.Label (new Rect(100,100,100,100),GetTime(tempTime));
}
void Update (){
tempTime -= Time.deltaTime;
}
string GetTime(float time){
if(time < 0){
return "00:00:00";
}
string lastTime = "";
float hour = Mathf.FloorToInt(time/3600%24);
if(hour/10 >= 1){
lastTime+="" + hour;
}else{
lastTime +="0" + hour;
}
float minute = Mathf.FloorToInt(time/60%60);
if(minute/10 >=1){
lastTime+=":" + minute;
}else{
lastTime +=":0" + minute;
}
float second = Mathf.FloorToInt(time%60);
if(second/10 >=1){
lastTime+=":" + second;
}else{
lastTime +=":0" + second;
}
return lastTime;
}