Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
-1
Question by Le-Capitaine · Apr 03, 2014 at 07:30 PM · menugetkeydown

[Solved] Menus advancing/returning several at a time

edit: Kudos to my man perchik for getting me out of it with style.

Here's my code. It's bloated and horrible -- my attempt at a generic piece of code for all menus didn't pan out -- but that's not really the problem. (Though I'll gladly have a tip or two on the side.)

         if (options) {
             if (optionsSelected == 3) {    
                 if (Input.GetKeyDown (controller.p1ButtonA) | Input.GetKeyDown (controller.p2ButtonA)) {
                     options = false;
                     sound = true;
                     }
             }
         }

         if (sound) {
             if (audioSelected == 4) {
                 if ((Input.GetKeyDown (controller.p1ButtonA) | Input.GetKeyDown (controller.p2ButtonA))) {
                     options = true;
                     sound = false;
                 }
             }
         }


In short, there's meant to be a "Back" item in the audio menu.

I think I get what happens -- the forward and back commands are both run in the same frame, and because I have a separate selector for each submenu (believe me, I tried), the "Back" item is triggered on the same keypress immediately after the audio menu is entered. The thing I can't figure out is how to set up my input so as to avoid this sort of keypress confusion.

edit: Well, I've tried a special coroutine for preventing double inputs...

     IEnumerator DoubleInputPrevention() {
         noPress = true;
         yield return new WaitForSeconds (0.25f);
         noPress = false;
     }

...and now the opposite happens -- the menu is never entered, because noPress is already true by the time the code gets to the relevant block.

I'm out of ideas.

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 getyour411 · Apr 07, 2014 at 09:49 PM 0
Share

Please don't use silly tags like "rocking in chair back and forth crying"

avatar image perchik · Apr 07, 2014 at 09:57 PM 0
Share

I think you may need to elaborate on what you want to do. Perhaps the solution is as simple as saying else if(sound) and that way when you set sound to true, it doesn't change before the second if statement

avatar image Le-Capitaine · Apr 08, 2014 at 07:02 AM 0
Share

"else"-ing it was what did it. A whole bunch of thanks and apologies for the silliness.

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

(Resolved) Load a Level by pressing a Key 1 Answer

Back Button menu navigation issue 1 Answer

How to make a GUI appear and disappear with the same button? 1 Answer

Game stopping at Pause? 1 Answer

How would I code in a music/sound option? 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