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)。

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

另一个例子:

  • C#
  • JavaScript
// 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;
	}
}

你可能感兴趣的:(Time.realtimeSinceStartup 自游戏开始实时时间)