Unity中Time.deltaTime的含義及其應用


The time in scenes it took to complete the last frame。這是使用此函數的時候給出的提示

一般我們會在設置速度的時候看到這個函數。先寫出我對Time.deltaTime的理解。即每秒物體移動的速度。注意,不是每幀物體移動的速度(如果是每幀的話,那跑的太快了。。。)。

如果你加上或者減去一個值,那你很可能應該乘以Time.deltaTime。

請注意,在OnGUI中你不應該依賴Time.deltaTime,因為OnGUI有可能在一幀中被多次調用並且每次deltatime的值都是相同的,直到下一幀刷新。

當從MonoBehavior的Fixedupdate中調用的時候,返回的幀速率增量時間。

以下是unity官方給出的示例代碼:

1 using UnityEngine;
2 using System.Collections;
3 
4 public class ExampleClass : MonoBehaviour {
5     void Update() {
6         float translation = Time.deltaTime * 10;
7         transform.Translate(0, 0, translation);
8     }
9 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM