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)无论实时渲染一帧所需要的时间。

一句话总结:设置游戏帧速率。

原文地址:https://www.cnblogs.com/leeplogs/p/8194143.html