public class timer : MonoBehaviour {
private float timer0 = 0f;
private int h = 0;//小时
private int m = 0;//分钟
private int s = 0;//秒
private string timeStr = string.Empty;
void Update()
{
timer0 += Time.deltaTime;
if (timer0 >= 1f) { s++;timer0 = 0; }
if (s >= 60) { m++; s = 0; }//满60秒后分钟+1
if (m >= 60) { h++; m = 0; }//满60分钟后小时+1
if (h >= 99) { h = 0; }//满99小时后清零
}
void OnGUI()
{
timeStr = string.Format("{0:D2}:{1:D2}:{2:D2}",h,m,s);//格式输出
GUI.Label(new Rect(10, 10, 100, 200), timeStr);//显示位置
}
}
07-18
870
12-22
2529