Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Time.realtimeSinceStartup 自游戏开始实时时间
# [Time](Time.html).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](Time.time.html) instead. 在几乎所有情况下,你应该使用 [Time.time](Time.time.html) 代替。 realtimeSinceStartup returns the time since startup, not affected by [Time.timeScale](Time.timeScale.html). 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](Time.timeScale.html) to zero, but still want to be able to measure time somehow. realtimeSinceStartup 返回时间自由行开始,不被 [Time.timeScale](Time.timeScale.html) 影响。即使被玩家暂停 realtimeSinceStartup 也将保持增加(在后台)。当你想通过设置 [Time.timeScale](Time.timeScale.html) 为 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](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { public void Awake() { print(Time.realtimeSinceStartup); } } ``` ``` // Prints the real time since start up. //打印自开始实时时间 print(Time.realtimeSinceStartup); ``` 另一个例子: * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : 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 = frames / timeNow - lastInterval; frames = 0; lastInterval = timeNow; } } } ``` ``` // 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; } } ```
da
2022年5月23日 14:36
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码