LoginSignup
3
9

More than 1 year has passed since last update.

【Unity】キー押下でゲーム終了をおこなう方法

Last updated at Posted at 2022-07-29

キー押下でゲーム終了をおこなう方法です。
GameManagerとかに書いてあげると良いかもしれません。

環境

Windows

コード

GameManager.cs
void Update() 
{
    Quit();
}

private void Quit() 
{
    if (Input.GetKey("escape")) {
        // UnityEditorの終了(ビルドでエラーになる場合は分岐にしてあげると良いです)
        UnityEditor.EditorApplication.isPlaying = false;
        Application.Quit();
    }
}

参考

3
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
9