Time.realtimeSinceStartup 自游戏开始实时时间

static var realtimeSinceStartup : float 

Description描述

The real time in seconds since the game started (Read Only).

以秒计,自游戏开始的实时时间(只读)。

In almost all cases you can and should use Time.time instead. 

在几乎所有情况下,你应该使用Time.time代替。

realtimeSinceStartup returns the time since startup, not affected by Time.timeScale. realtimeSinceStartup also keeps increasing while the player is paused (in the background). Using realtimeSinceStartup is useful when you want to pause the game by setting Time.timeScale to zero, but still want to be able to measure time somehow. 

realtimeSinceStartup返回时间自由行开始,不被Time.timeScale影响。即使被玩家暂停realtimeSinceStartup也将保持增加(在后台)。当你想通过设置Time.timeScale为0暂停游戏时,使用realtimeSinceStartup是很有用的,但仍希望能够以某种方式来计算时间。

Note that realtimeSinceStartup returns time as reported by system timer. Depending on the platform and the hardware, it may report the same time even in several consecutive frames. If you're dividing something by time difference, take this into account (time difference may become zero!).

请注意, realtimeSinceStartup返回时间来源于系统的计时器。根据不同的平台和硬件,也行会在一些连贯的帧上报告相同的时间,如果通过不同的时间来区分不同的事情,要考虑到这点(时间不同可能变为0)。

// Prints the real time since start up.
//打印自开始实时时间
print(Time.realtimeSinceStartup);

另一个例子:

// A FPS counter. 一个FPs计时器
// It calculates frames/second over each updateInterval,
// so the display does not keep changing wildly.
//在每个updateInterval间隔处计算,帧/秒,这样显示就不会随意的改变
var updateInterval = 0.5;
private var lastInterval : double; // Last interval end time 最后间隔结束时间
private var frames = 0; // Frames over current interval 超过当前间隔帧
private var fps : float; // Current FPS //当前FPS

function Start() {
	lastInterval = Time.realtimeSinceStartup;
	frames = 0;
}

function OnGUI () {
	// Display label with two fractional digits
	//在标签显示两位小数
	GUILayout.Label("" + fps.ToString("f2"));
}

function Update() {
	++frames;
	var timeNow = Time.realtimeSinceStartup;
	if( timeNow > lastInterval + updateInterval )
	{
		fps = frames / (timeNow - lastInterval);
		frames = 0;
		lastInterval = timeNow;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值