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 /
  • Help Room /
This question was closed Mar 21, 2016 at 06:42 PM by Le-Pampelmuse for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by etaxi341 · Jun 28, 2014 at 05:36 PM · movementinputupdatewalkinggetkeydown

GetKeyUp does not get called sometimes.

Hello Community. My problem is that sometimes the GetKeyUp does not get called!

My Code:

     void Update()
     {
         if (Input.GetKeyDown(KeyCode.D))
         {
             walking = true;
         }
         else if (Input.GetKeyUp(KeyCode.D))
         {
             walking = false;
         }
         print (walking);
     }

So sometimes the Console tells me true even if I have already stopped pressing "D".

Thank you :)

(And No I can not use GetKey instead of this 2 Calls cause I need to know when it is not pressed anymore)

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

  • Sort: 
avatar image
1
Best Answer

Answer by NoseKills · Jun 28, 2014 at 10:52 PM

I'm not aware of a bug that would cause GetKeyUp to not trigger. Put a print in both the keyDown and keyUp to see if the Up case really doesn't get fired. Also make sure you are not setting walking to true anywhere else.

Not sure what you mean by

(And No I can not use GetKey instead of this 2 Calls cause I need to know when it is not pressed anymore)

Shouldn't this work in any case?

     var wasWalking:bool;
     void Update()
     {
         walking = Input.GetKey(KeyCode.D);
         if (wasWalking)
         {
             if (!walking)
             {
                 // key was released
             }
         }
         else 
         {
             if (walking)
             {
                 // key was pressed
             }
         }
         wasWalking= walking;
         print (walking);
     }

This way "walking" will be true when D is pressed and false if not, and if you need to do something special the frame when it's pressed or released, you can do it in the if/else. If not, just erase the whole if/else

Comment
Add comment · Show 1 · 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 etaxi341 · Jun 29, 2014 at 05:36 AM 0
Share

Thank you! Now it works. Didn't think of that! You are awesome :)

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GetKeyDown Not Functioning When Two Unrelated GetKeys are True 0 Answers

Custom Movement Script Not Registering Input 1 Answer

Can Someone Help me With Some Input Issues? 0 Answers

How can I move a game object/camera along a defined path with a speed defined by input of a (bluetooth) keyboard? 0 Answers

How do I adjust code so gyro translates player to center position when device is being held in hands 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