(Unity)ボタンを押してゲーム内の時間の流れを止める方法

  • zキーを押したら時間の流れが遅くなる。
  • 一定時間が経過したら元に戻る。

*時間の流れを早くすることももちろん可能。


(スクリプト)

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

public class StopTime : MonoBehaviour
{
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Z))
        {
            Time.timeScale = 0.1f;
            Invoke("Reset", 1.0f);
        }
    }

    private void Reset()
    {
        Time.timeScale = 1.0f;
    }
}