UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Time.timeScale
# [Time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time.html).timeScale public static float **timeScale** ; ## 描述 时间流逝的标度。可用于慢动作效果。 当 `timeScale` 为 1.0 时,时间流逝的速度与实时一样快。 当 `timeScale` 为 0.5 时,时间流逝的速度比实时慢 2x。 当 `timeScale` 设置为 0 时,如果您的所有函数都是独立于帧率的, 则游戏基本上处于暂停状态。 `timeScale` 影响 [Time](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time.html) 类的所有时间和增量时间测量变量(但 [realtimeSinceStartup](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-realtimeSinceStartup.html) 和 [fixedDeltaTime](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-fixedDeltaTime.html) 除外)。 如果您减小了 /timeScale/,建议也将 [Time.fixedDeltaTime](https://docs.unity3d.com/cn/2019.4/ScriptReference/Time-fixedDeltaTime.html) 减小相同的量。 当 `timeScale` 设置为 0 时,不会调用 [FixedUpdate](https://docs.unity3d.com/cn/2019.4/ScriptReference/MonoBehaviour.FixedUpdate.html) 函数。 ``` using UnityEngine; public class Example : MonoBehaviour { // Toggles the time scale between 1 and 0.7 // whenever the user hits the Fire1 button. private float fixedDeltaTime; void Awake() { // Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor this.fixedDeltaTime = Time.fixedDeltaTime; } void Update() { if (Input.GetButtonDown("Fire1")) { if (Time.timeScale == 1.0f) Time.timeScale = 0.7f; else Time.timeScale = 1.0f; // Adjust fixed delta time according to timescale // The fixed delta time will now be 0.02 frames per real-time second Time.fixedDeltaTime = this.fixedDeltaTime * Time.timeScale; } } } ```
da
2022年6月21日 11:28
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码