Time.deltaTime 增量时间

static var deltaTime : float

Description描述

The time in seconds it took to complete the last frame (Read Only).

以秒计算,完成最后一帧的时间(只读)。

Use this function to make your game frame rate independent.

使用这个函数使和你的游戏帧速率无关。

放在Update()函数中的代码是以帧来执行的.如果我们需要物体的移动以秒来执行.我们需要将物体移动的值乘以Time.deltaTime。

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.

当从MonoBehaviourFixedUpdate里调用时,返回固定帧速率增量时间(fixedDeltaTime)。

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将持有相同的值,直到下一帧再次更新。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Update() {
		float translation = Time.deltaTime * 10;
		transform.Translate(0, 0, translation);
	}
}
function Update () {
	// Move the object 10 meters per second!
	//每秒移动物体10米
	var translation : float = Time.deltaTime * 10;
	transform.Translate (0, 0, translation);
}
Page last updated: 2010-12-26