Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Time.timeScale 时间缩放
# [Time](Time.html).timeScale 时间缩放 static var *timeScale* : float *Description* 描述 The scale at which the time is passing. This can be used for slow motion effects. 传递时间的缩放。这可以用于减慢运动效果。 When timeScale is 1.0 the time is passing as fast as realtime. When timeScale is 0.5 the time is passing 2x slower than realtime. 当 timeScale 传递时间 1.0 时和实时时间一样快。当 timeScale 传递时间 0.5 时比实时时间慢一半。 When timeScale is set to zero the game is basically paused if all your functions are frame rate independent. 当 timeScale 传递时间为 0 时游戏基本上暂停了,如果你的所有函数是和帧速率无关的。 Except for [realtimeSinceStartup](Time.realtimeSinceStartup.html), timeScale affects all the time and delta time measuring variables of the [Time](Time.html) class. 除了 [realtimeSinceStartup](Time.realtimeSinceStartup.html),timeScale 影响所有时间和增量时间基于 [Time](Time.html) 类的变量。 If you lower timeScale it is recommended to also lower [Time.fixedDeltaTime](Time.fixedDeltaTime.html) by the same amount. 如果降低 timeScale,建议也降低 [Time.fixedDeltaTime](Time.fixedDeltaTime.html) 同样的数值。 [FixedUpdate](../MonoBehaviour/MonoBehaviour.FixedUpdate.html) functions will not be called when timeScale is set to zero. 当 timescale 设置为 0 时,[FixedUpdate](../MonoBehaviour/MonoBehaviour.FixedUpdate.html) 函数将不会被调用。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { if (Input.GetButtonDown("Fire1")) { if (Time.timeScale == 1.0F) Time.timeScale = 0.7F; else Time.timeScale = 1.0F; Time.fixedDeltaTime = 0.02F * Time.timeScale; } } } ``` ``` // Toggles the time scale between 1 and 0.7 // whenever the user hits the Fire1 button. //切换时间缩放在1-0.7之间,每当用户点击Fire1按钮。 function Update () { if (Input.GetButtonDown ("Fire1")) { if (Time.timeScale == 1.0) Time.timeScale = 0.7; else Time.timeScale = 1.0; // Adjust fixed delta time according to timescale // The fixed delta time will now be 0.02 frames per real-time second //根据timescale调整固定增量时间。 Time.fixedDeltaTime = 0.02 * Time.timeScale; } } ```
da
2022年5月23日 14:37
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码