Time类里面time、deltaTime、fixedTime、fixedDeltatime的区别(Unity3d)

Time类里面time、deltaTime、fixedTime、fixedDeltatime的区别(Unity3d)

time是从程序开始执行到现在的时间,deltaTime上一帧完成的时间,fixedTime表示FixedUpdate已经执行的时间,而fixedDeltatime是一个固定的时间增量。

在update()中time、deltaTime获取的是一个正确的值,fixedTime的值并不会增加,如果是在FixedUpdate

中,则fixedTime值会更新并且和time的值一样,deltaTime和fixedDeltatime的值一样。注意除了fixedDeltatime其他3个值都是只读的,可以通过fixedDeltatime来改变FixedUpdate的跟新速率。

void Update () {
        Debug.Log("在Update中执行");
        Debug.Log("time:"+Time.time);
        Debug.Log("deltatime"+Time.deltaTime);
        Debug.Log("fixedtime:"+Time.fixedTime);
        Debug.Log("fixedDeltatimetime:" + Time.fixedDeltaTime); 
}
    void FixedUpdate()
    {
        Debug.Log("在fixedUpdate中执行");
        Debug.Log("time:" + Time.time);
        Debug.Log("deltatime" + Time.deltaTime);
        Debug.Log("fixedtime:" + Time.fixedTime);
        Debug.Log("fixedDeltatimetime:" + Time.fixedDeltaTime); 
    }


猜你喜欢

转载自blog.csdn.net/qq_39887964/article/details/79627838
今日推荐