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 /
avatar image
0
Question by Westy00 · Apr 30, 2018 at 09:10 AM · unity 5javascriptkeycodedouble-click

GetKeyDown held for too long

Hi, I have a script that loads through overviews of levels but only lets you go to the next level if you have 3 stars in the current one, I am using the bumpers on an xbox controller to change between level however if you are on level one and click right bumper it takes you to level 3 if you have 3 stars on level 2 already. I have tried to change where the input is on the code. The problem is because when I load up level 2 selection it sets the level selection to 2, and then it has the 3 stars so instantly jumps up again, this is all in function so cannot have a wait code in it as I have tried that, any help?

 if (Input.GetKeyDown(KeyCode.Joystick1Button5))
         {
         if (level_selection == 1)
             {
             if (PlayerPrefs.HasKey("Hedge_10x10_01_Stars"))
                 {
                 if (PlayerPrefs.GetInt("Hedge_10x10_01_Stars") >= 3)
                     {
                     level_selection += 1;
                     }
                 }
             }
         if (level_selection == 2)
             {
             if (PlayerPrefs.HasKey("Hedge_10x10_02_Stars"))
                 {
                 if (PlayerPrefs.GetInt("Hedge_10x10_02_Stars") >= 3)
                     {
                     level_selection += 1;
                     }
                 }
             }
         if (level_selection == 3)
             {
             if (PlayerPrefs.HasKey("Hedge_10x10_03_Stars"))
                 {
                 if (PlayerPrefs.GetInt("Hedge_10x10_03_Stars") >= 3)
                     {
                     level_selection += 1;
                     }
                 }
             }
 
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

1 Reply

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

Answer by Captain_Pineapple · Apr 30, 2018 at 01:38 PM

If i got your question right you want it to change only one level per buttonDown? Then just change your if(levelselection == x) to an if/else if/else if statement istead of the current if/if/if. That way only one of the cases will be active per click.

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 Westy00 · Apr 30, 2018 at 02:39 PM 0
Share

Thank you very much, it works perfectly now

avatar image Captain_Pineapple Westy00 · May 01, 2018 at 12:28 PM 0
Share

Note at this point that you can not "hold a button too long" when you use Get$$anonymous$$eyDown. It will always trigger only once per button click. Perhaps read into the difference between Get$$anonymous$$eyDown/Get$$anonymous$$ey/Get$$anonymous$$eyUp

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

206 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

Related Questions

I need help with a CharacterMotor script error in Unity5. This is formatted in Javascript. 0 Answers

Moving Animations 3 Answers

Need help with combining meshes 1 Answer

Why am I only allowed to trigger my dash script once? 2 Answers

How do perform the operations as per the commands at client side in socket unity? 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