Unity中的TimeScale

  TimeScale的默认值是1,TimeScale的值大小对Update和LateUpdate没有影响,但是对FixedUpdate有影响。TimeScale越大,FixedUpdate执行越快,越小执行越慢,0时不执行,不能小于0。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    public float timeScaleParams;
    // Start is called before the first frame update
    void Start()
    {
        timeScaleParams = 1;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
                    Time.timeScale = timeScaleParams;
        }
        Debug.Log("Update");
    }


    void LateUpdate()
    {
        Debug.Log("LateUpdate"); 
    }

    void FixedUpdate()
    {
        Debug.Log("FixedUpdate");  
    }
}

详解参考Unity关于Time.timeScale详解

你可能感兴趣的:(Unity)