Time.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, timeScale affects all the time and delta time measuring variables of the Time class.
除了realtimeSinceStartup,timeScale影响所有时间和增量时间基于Time类的变量。
If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.
如果降低timeScale,建议也降低Time.fixedDeltaTime同样的数值。
FixedUpdate functions will not be called when timeScale is set to zero.
当timescale设置为0时,FixedUpdate函数将不会被调用。
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;
}
}