Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by hyeqt100 · Jul 07, 2018 at 08:36 PM · menupausepause menupause gameonkeydown

Pause Menu open/close on key

I'm trying to get my pause menu to open and close when the player presses the "p" key. The buttons on the pause menu work to take you to the main menu and quit the game, but for some reason, the menu won't activate/deactivate once the "p" key is pressed. At first I created the menu in its own scene, but I've added it to my level to see if it would make a difference (it didn't)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class PauseMenu : MonoBehaviour
 {
     
     public static bool GameIsPaused = false;
 
     public GameObject PauseMenuBehavior;
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.P))
         {
             if (GameIsPaused)
             {
                 Resume();
             }
             else
             {
                 Pause();
             }
         }
     }
     public void Resume()
     {
         PauseMenuBehavior.SetActive(false);
         Time.timeScale = 1f;
         GameIsPaused = false;
     }
     public void MainMenu()
     {
         Time.timeScale = 1f;
         SceneManager.LoadScene("Main_Menu");
     }
     void Pause()
     {
         PauseMenuBehavior.SetActive(true);
         Time.timeScale = 0f;
         GameIsPaused = true;
     }
     public void QuitGame()
     {
         Application.Quit();
         Debug.Log("Quitting game...");
     }
 }
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image imM4TT · Jul 07, 2018 at 10:18 PM 0
Share

Do the game resume well but the pause screen didnt't disappears ?

avatar image hyeqt100 imM4TT · Jul 07, 2018 at 10:49 PM 0
Share

no it doesn't resume

avatar image imM4TT hyeqt100 · Jul 07, 2018 at 10:54 PM 0
Share

Yes, maybe try to change the line of your boolean GameIsPaused at line 42 before the Time.timeScale equal to zero ?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by seandolan · Jul 08, 2018 at 02:18 AM

I used your exact code. It's working perfectly for me. The code looks the same as the Brakeys tutorial (https://www.youtube.com/watch?v=JivuXdrIHK0) but I think maybe the buttons on your pause menu are overriding your P key input. If you have buttons on your pause menu try setting the Navigation option on the button to None and test. I think you will find this is the problem. The Navigation option does things like accepting Spacebar to click a button. Image attached of where to set this option.

example


button.png (20.6 kB)
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hyeqt100 · Jul 08, 2018 at 04:12 AM 0
Share

thanks, that is the video I watched! I'll try that tomorrow!

avatar image hyeqt100 · Jul 08, 2018 at 11:42 PM 0
Share

So I changed all the menu buttons to "none" and now the menu closes, but it doesn't open :/

avatar image xboy691 hyeqt100 · Jul 09, 2018 at 03:18 AM 0
Share

If this script is on the actual menu object that you're setting as inactive, then it wouldn't be able to open itself back up because it's no longer active. If this is the case, make sure this script is sitting on an object that isn't being set as inactive.

avatar image hyeqt100 xboy691 · Jul 09, 2018 at 07:09 PM 0
Share

I feel so stupid, that's what the problem was! I attached it to my Pause$$anonymous$$enuBehavior game object which stays active and now I can pause and resume freely ^_^ thank you so much!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to pause the mouselook script during pause? 1 Answer

GUI Buttons not working after scene transition 0 Answers

Game stopping at Pause? 1 Answer

Locked Cursor when Game Paused 1 Answer

Pause Menu Buttons Not Working on First Attempt 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges