Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 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 /
  • Help Room /
avatar image
0
Question by wriggling_moray · Nov 22, 2021 at 04:50 PM · uicanvasmenupausepause menu

Pause menu not called when ESC pressed

Hello everyone!

For my first project I am trying to create a simple PAUSE menu. Once per frame there is a check if ESC is pressed. If yes, than it sets boolean value to true, toggles off Canvas 1 (UI) and toggles on Canvas 2 (pause menu) with multiple buttons. If then ESC is pressed again it reverses the changes (1 on, 2 off, false).

The buttons already work, but the pressing of ESC does nothing. If I manually toggle on Canvas 2 it does toggle off when pressing ESC though.

Thank you in advance for any advice!

Code below: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour { bool pausedGame = false; public GameObject CanvasA; public GameObject CanvasB;

 // Start is called before the first frame update
 void Start()
 {
     CanvasA.gameObject.SetActive(false); //Toggle off when starting
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown("escape"))
     {
         if (!pausedGame) 
         {
             pausedGame = true;
             CanvasA.gameObject.SetActive(true);
             CanvasB.gameObject.SetActive(false);
         }
         else
         {
             pausedGame = false;
             CanvasA.gameObject.SetActive(false);
             CanvasB.gameObject.SetActive(true);
         }
     }
 }

 void OnContinueButton()
 {
     CanvasA.gameObject.SetActive(false);
     CanvasB.gameObject.SetActive(true);
 }

 void OnRestartButton()
 {
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
 }

 void OnMainMenuButton()
 {
     SceneManager.LoadScene(0);
 }

 void OnQuitButton()
 {
     Application.Quit();
 }

}

Comment
Add comment · Show 1
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 wriggling_moray · Nov 22, 2021 at 03:36 PM 0
Share

Quick update:

I manage to make it work. Solution was also putting script on Canvas B and not only A as well as disabling the start() function. Though I do not really understand why calling it made Canvas A untoggable for the rest of the runtime...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by lvskiprof · Nov 22, 2021 at 05:48 PM

Have you tried using Debug.Log() to show you how the logic is behaving?

I am wondering if you are detecting that the Escape key is down multiple times. Frankly, I am not sure if you only get a single response from the key being pressed or if you might get that response as long as the key is pressed.

Just put some Debug.Log() output inside your if-else blocks and see what it is doing and you should be able to figure it out by watching the Console output.

Comment
Add comment · 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
0

Answer by Dsiak · Nov 24, 2021 at 01:04 AM

I copy and pasted your code on a testing project and it works fine, the problem might be on another script that is conflicting with your Main Menualt text


ezgifcom-gif-maker.gif (447.4 kB)
Comment
Add comment · 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

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

272 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i stop my mouse from being in first person when a pause menu appears? 0 Answers

How do i move a canvas? 0 Answers

Problem with animated image on canvas 0 Answers

How to stop the game but not the menu animations? 0 Answers

Invenotry system for other objects 0 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