游戏开始以来的实际时间(只读)。
In almost all cases you can and should use Time.time instead.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
返回系统计时器报告的时间。
根据平台和硬件的不同,它可能会在数个连续帧中报告相同的时间。
如果您需要用某个值除以时间差,一定要考虑到这一点
(时间差可能会变为 0!)。
using UnityEngine; using System.Collections;
// An FPS counter. // It calculates frames/second over each updateInterval, // so the display does not keep changing wildly. public class ExampleClass : MonoBehaviour { public float updateInterval = 0.5F; private double lastInterval; private int frames = 0; private float fps; void Start() { lastInterval = Time.realtimeSinceStartup; frames = 0; }
void OnGUI() { GUILayout.Label("" + fps.ToString("f2")); }
void Update() { ++frames; float timeNow = Time.realtimeSinceStartup; if (timeNow > lastInterval + updateInterval) { fps = (float)(frames / (timeNow - lastInterval)); frames = 0; lastInterval = timeNow; } } }