在Unity中有两个和Frame有关的回调函数,一个是Update,另一个是FixedUpdate,在这两个函数中都可以安全地获取Time.deltaTime的值,那么有什么细微的差别呢?
1. 先看看官方文档对此的解释
The completion time in seconds since the last frame (Read Only).
This property provides the time between the current and previous frame.
这个属性是一个浮点数,表示当前时刻到上一帧所经过的秒数。
所以关键就在这里,上一帧究竟指什么?
2. 设计测试代码
纸上得来终觉浅,绝知此事要躬行,不妨设计一个简单的测试代码来分析一下。
在场景中添加一个名为“DeltaTimeTester”的GameObject,为其添加一个脚本组件“DeltaTimeTesterController“,分别在Update函数和FixedUpdate函数中输出log,具体代码为下:
using System.Collections