Version: 2017.3

Time.deltaTime

切换到手册
public static float deltaTime ;

描述

完成上一帧所用的时间(以秒为单位)(只读)。

使用该函数可以让您的游戏独立于帧率。

如果您在每一帧中添加或减去一个值,则您可能应该乘以 Time.deltaTime。 与 Time.deltaTime 相乘的基本含义是: 我需要让该对象每秒移动 10 米,而不是每帧移动 10 米。

从 MonoBehaviour 的 FixedUpdate 内部调用时, 返回固定帧率增量时间。

注意,您不应该依赖 OnGUI 内部的 Time.deltaTime, 因为每帧可以多次调用 OnGUI,并且 deltaTime 将在每次调用时保持相同的值, 直到下一帧才进行更新。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { float translation = Time.deltaTime * 10; transform.Translate(0, 0, translation); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961