Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Pause Menu On Button Down

Discussion in 'Scripting' started by CamRidesBikes, Jun 10, 2020.

  1. CamRidesBikes

    CamRidesBikes

    Joined:
    Nov 21, 2019
    Posts:
    1
    I am trying to make a pause menu when the Escape key is pressed. How would I do this.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PauseMenu : MonoBehaviour
    6. {
    7.     public bool gameIsPaused = false;
    8.  
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.         if (Input.GetKeyDown("Escape"))
    13.         {
    14.             gameIsPaused = true;
    15.             Debug.Log("Paused");
    16.  
    17.         }
    18.     }
    19. }
    20.  
     
  2. busterlock

    busterlock

    Joined:
    Sep 26, 2015
    Posts:
    58
    Your code is ok, the only problem with it is the Input function, there's a typo there, it should be:
    Code (CSharp):
    1. if (Input.GetKeyDown("escape"))
    2. {
    3.    gameIsPaused = true;
    4.    Debug.Log("Paused");
    5. }
    Just change that "Escape" for "escape" and everything else should work just fine...