Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ArnauRapid · May 14, 2018 at 10:07 PM · menukeyblock

Block Escape key while using SubMenu

I have a pause menu that gets activated when pressing Escape. In that menu I have a series of buttons that when clicking on, close the previous menu and open a new panel with the option of going backwards. The thing is that if I press Escape once inside of the second panel, the initial pause menu overlays. My intention is to block the key Escape when the second menu is on, so it doesn't happen but I don't know how :/

Any clues/method I could try?

Thank you

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Darkforge317 · May 14, 2018 at 10:48 PM

Can you please show the code? It would help a lot.

Here's my advice without seeing the code though... Create an enum and call it PauseState. This enum should have as many states as there are panels... So if you have the MainPause panel and a settings panel, then make sure the enum has "Main" and "Settings" as possible states.

     public enum PauseState
     {
         Main,
         Settings
     }
 
     PauseState myState = PauseState.Main;

Now, whenever you click on the button for settings, simply set myState to PauseState.Settings.

     public void SettingsButton()
     {
         // Turn off the main panel
         mainPanel.SetActive(false):
 
         // Turn on the settings panel
         settingsPanel.SetActive(true):
 
         // We're now in the settings menu
         myState = PauseState.Settings;
     }

That way, when you press Escape, you can check if myState is Main or not.

         // If we press Escape
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             // If we're currently paused
             if(isPaused)
             {
                 // If we're on the main panel
                 if(myState == PauseState.Main)
                 {
                     // Unpause the game
                     Unpause();
                 }
             }
             // If we're not currently paused
             else
             {
                 // Pause the game
                 Pause();
             }
         }

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 ArnauRapid · May 15, 2018 at 12:50 AM

Thank you for your answer @Darkforge317 :D, I understand that my problem can be a little bit confusing, that's why I did these gifs to try to show better what is the issue I am facing. Here you can see how I access the game and when pressing Escape and accessing the audiosettings the pause menu overlays the audio settings menu. This is what I am trying to avoid.alt text

As you can see in my Hierarchy I have different panels and I change between them by using the OnClick() options setting active or unactive their visibility. To fix the problem with the Escape I was trying to play with the interactability and alpha map of the PausePanel. This is how I did a script called BlockEscape that reads like this:

 public CanvasGroup pausePanel;
 public bool subMenuClicked = false;

 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         if (subMenuClicked == false)
         {
             pausePanel.alpha = 1;
             pausePanel.interactable = true;
             pausePanel.blocksRaycasts = true; 
         }
         else
         {
             pausePanel.alpha = 0;
             pausePanel.interactable = false;
             pausePanel.blocksRaycasts = false;
         }
                
     }

however that works half way because although it avoids the overlay, it doesn't show the pause panel menu anymore after leaving the audio settings even if I press Escape. Check the following gif: alt text

I don't know what to do next.


mainproblemcompress.gif (424.0 kB)
problempossiblesolutioncompress.gif (493.2 kB)
Comment
Add comment · Show 2 · 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 Darkforge317 · May 15, 2018 at 01:23 AM 0
Share

Did you try the code in my answer?

Your problems look like they can be solved by my code...

avatar image ArnauRapid · May 15, 2018 at 01:39 PM 0
Share

@Darkforge317 yes, I tried your code, but while testing it I could see that what I was trying to fix with a boolean (sub$$anonymous$$enuClicked) you were trying with an Enum. In the end I decided to fix this issue by using the following code:

 public CanvasGroup pausePanel; //Invocation to access the interaction and alpha of the panel
 public GameObject audioPanel; //Audio Settings Panel

 void Update()
 {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
     {
        if (audioPanel.activeInHierarchy == true)
        {
             pausePanel.alpha = 0;
             pausePanel.interactable = false;
             pausePanel.blocksRaycasts = false;
         }
         else
         {
             pausePanel.alpha = 1;
             pausePanel.interactable = true;
             pausePanel.blocksRaycasts = true;
         }
                
     }

however this is far from what I wanted to achieve and it feels just like a bandaid because what I wanted was to cancel the Escape key the moment the audio panel would be ON. Right now, the key still works but the content doesn't show because I made it disappear by modyfing the alpha and blocking any possible interaction with it.

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

139 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

Related Questions

Is it possible to call a block from a fungus flowchart in the different scene? 1 Answer

How do you do a dropdown menu that changes resolution? 0 Answers

how to tell what scene the player was previously in 1 Answer

Strange bug while navigating in menus 0 Answers

Control animator animation with UI Slider 1 Answer


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