关于unity计时问题

创建一个GUI Texture,将下面代码挂上即可


#pragma strict



//个人原创,转载请声明转载自 http://www.cnblogs.com/suxsho


//计时器




var hour : int = 12; //时
var min : int = 30; //分
var sec : int = 0; //秒




//固定记时


var timeRate : float = 0.01; //修改时间
private var nextTime : float = 1.0; //这个不动


function Start()
{


}
function Update () {


guiText.text = hour.ToString()+":"+min.ToString()+":"+sec.ToString();



time();


}


function time ()
{


//记时
if (Time.time > nextTime) 
{
nextTime = Time.time + timeRate;
sec ++; 
}


//分钟计算


if (sec >= 60)
{
sec = 0;
min ++;
}


if (min >= 60)
{
min = 0;
hour ++;
}


if (hour >= 24)
{
hour = 0;
}


}

你可能感兴趣的:(unity)