2018年了,新年老是會制定不少具體目標和計劃,無論可否堅持去完成,初衷和決心老是要有的。本年第一篇博客終於開始下筆了,先立一些今年和公司業務無關的的flag:html
官方API https://docs.unity3d.com/ScriptReference/Time.htmlless
Time.deltaTime(只讀)ide
unity官方解釋爲:函數
The time in seconds it took to complete the last frame (Read Only).性能
以秒計算,完成最後一幀的時間(只讀)。ui
Use this function to make your game frame rate independent. this
使用這個函數使和你的遊戲幀速率無關。spa
一句話總結:指的是當前時間節點的上一幀所用的時間。3d
void Update () { //方式1 // gameObject.transform.Translate(new Vector3(0,0,10)); //方式2 gameObject.transform.Translate (new Vector3 (0, 0, 10) * Time.deltaTime); }
方式1 表示 : Update函數每幀調用一次,也便是說每一幀物體都會向前移動10m,不能保證勻速,由於每一幀的時間間隔不必定相同code
方式2表示 : 執行當前幀的時候移動前一幀所用的時間*10m,從第二幀開始以10m/s的速度移動。
Time.time(只讀)
unity官方解釋爲:
The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game.
此幀開始時的時間(只讀)。這是遊戲開始後以秒爲單位的時間。
Returns the same value if called multiple times in a single frame. When called from inside MonoBehaviour's FixedUpdate, returns fixedTime property.
若是在同一幀中屢次調用,則返回相同的值。當在MonoBehaviour的FixedUpdate中調用,返回固定時間。
Time.fixedTime(只讀)
The time the latest FixedUpdate has started (Read Only). This is the time in seconds since the start of the game.
最近的FixedUpdate幀開始的時間(只讀)。這是遊戲開始後以秒爲單位的時間。
Fixed time is updated in regular intervals (equal to fixedDeltaTime) until time property is reached.
當知足時間性能時,固定時間會按期更新(至關於fixeddeltatime)。
Time.timeScale(可寫)
Time.timeScale影響的是Unity的遊戲時間縮放比例.
記住下面兩句話:
1.「timeScale不會影響Update和LateUpdate的執行速度」
2.「FixedUpdate是根據時間來的,因此timeScale只會影響FixedUpdate的速度」。
官方的一句話:
Except for realtimeSinceStartup, timeScale
affects all the time and delta time measuring variables of the Time class.
除了realtimesincestartup,timeScale影響Time類中全部時間和時間增量測量相關的變量。
Time.captureFramerate(可寫)
unity官方解釋爲:
Slows game playback time to allow screenshots to be saved between frames.
減慢遊戲播放時間,容許幀與幀之間截圖。
If this property has a non-zero value then frame update will occur at an interval of (1.0 / captureFramerate) regardless of real time and the time required to render a frame.
若是這個屬性有一個非零的值,而後架更新將發生在一個區間(1 / captureframerate)不管實時渲染一幀所須要的時間。
一句話總結:設置遊戲幀速率。