unity -- Time類(持續更新中)


2018年了,新年總是會制定很多具體目標和計划,不管能否堅持去完成,初衷和決心總是要有的。本年第一篇博客終於開始下筆了,先立一些今年和公司業務無關的的flag:

1.希望每月或兩月能看一套蠻牛游戲上的教程
2.少追肥皂劇多讀書
3.少矯情少想男人多更博
 
好吧,不廢話了,言歸正傳,下面開始總結新年第一個知識點:Time類

官方API  https://docs.unity3d.com/ScriptReference/Time.html

 

Time.deltaTime(只讀)

unity官方解釋為:

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

以秒計算,完成最后一幀的時間(只讀)。

Use this function to make your game frame rate independent. 

使用這個函數使和你的游戲幀速率無關。

一句話總結:指的是當前時間節點的上一幀所用的時間。

    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,不能保證勻速,因為每一幀的時間間隔不一定相同

方式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)無論實時渲染一幀所需要的時間。

一句話總結:設置游戲幀速率。

 


免責聲明!

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



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