Unity Time的使用

脚本语言:C#

1、deltatime:

  deltatime它表示距上一次调用Update或FixedUpdate所用的时间,调用deltatime可以使物体的旋转以一种恒定的速度来运行,而不受帧速率的控制或计算机性能的影响。

2、time变量的使用:

  表示自游戏开始以来所经历的时间。

3、实例:

  创建一个脚本TimeShow,添加到主摄像机物体Main Camera中,脚本代码如下:

using UnityEngine;
using System.Collections;

public class TimeShow : MonoBehaviour {

    // Use this for initialization
    void Start () {
    }
    
    // Update is called once per frame
    void Update () {
    }

    void OnGUI(){
        GUILayout.Label ("当前时间是:"+Time.time);
        GUILayout.Label ("上一帧消耗的时间是:"+Time.deltaTime);
        GUILayout.Label ("固定增量时间是:"+Time.fixedTime);
        GUILayout.Label ("固定增量间隔时间是:"+Time.fixedDeltaTime);
        GUILayout.Label ("平滑DeltaTime:"+Time.smoothDeltaTime);
    }
}

可以看到时间类中的变量值在游戏窗中显示如下:

原文地址:https://www.cnblogs.com/vitah/p/3842705.html