UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Time.time
# [Time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time.html).time public static float **time** ; ## 描述 该帧开始的时间(只读)。此为自游戏启动以来的时间(以秒为单位)。 Time.time 是应用程序已运行的时间(以秒为单位)。它是只读的。 应用程序在每帧开始时接收当前的 [Time.time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-time.html),该值按帧递增。每个帧的 [time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-time.html) 调用将接收相同的值。在从 `FixedUpdate` 中调用时,将返回 [Time.fixedTime](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-fixedTime.html) 属性。 应避免常规的(每帧)调用:[Time.time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-time.html) 倾向于提供应用程序已经运行的时间长度,而不是每帧的时间。 [Time.time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-time.html) 的值在 `Awake` 消息期间未定义,将在所有消息完成后开始。 ``` using System.Collections; using System.Collections.Generic; using UnityEngine; public class Example : MonoBehaviour { private int width, height; private Rect rect; private GUIStyle labelStyle; private string currentTime; void Awake() { width = Screen.width; height = Screen.height; rect = new Rect(10, 10, width - 20, height - 20); } void OnGUI() { // Display the label at the center of the window. labelStyle = new GUIStyle(GUI.skin.GetStyle("label")); labelStyle.alignment = TextAnchor.MiddleCenter; // Modify the size of the font based on the window. labelStyle.fontSize = 12 * (width / 200); // Obtain the current time. currentTime = Time.time.ToString("f6"); currentTime = "Time is: " + currentTime + " sec."; // Display the current time. GUI.Label(rect, currentTime, labelStyle); } } ```
da
2022年6月21日 11:28
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码