unity3d学习j记录之 API阅读-002Time.deltaTime

来源:互联网 发布:中科院物理所考研知乎 编辑:程序博客网 时间:2024/05/29 03:01

Time.deltaTime


public static float deltaTime;

Description 描述

The time in seconds it took to complete the last frame (Read Only).完成最后一帧所需的时间(只读)。

Use this function to make your game frame rate independent.使用此功能可以使您的游戏帧速率独立。

If you add or subtract to a value every frame chances are you should multiply with Time.deltaTime. When you multiply with Time.deltaTime you essentially express: I want to move this object 10 meters per second instead of 10 meters per frame.

如果您在每一帧添加或减去一个值,您应该与Time.deltaTime相乘。当您乘以Time.deltaTime您本质上表达:我想移动这个对象每秒10米,而不是每帧10米。

When called from inside MonoBehaviour's FixedUpdate, returns the fixed framerate delta time.

调用时,返回固定的帧速率增量时间。

Note that you should not rely on Time.deltaTime from inside OnGUI since OnGUI can be called multiple times per frame and deltaTime would hold the same value each call, until next frame where it would be updated again.注意,您不应该依赖OnGUI中的Time.deltaTime,因为OnGUI可以每帧调用多次,deltaTime将保持每个调用相同的值,直到下一帧再次被更新。

public class ExampleClass : MonoBehaviour {    void Update() {        float translation = Time.deltaTime * 10;        transform.Translate(0, 0, translation);    }}
原创粉丝点击