Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 Happystudio · Mar 19, 2018 at 12:00 AM · inputkeyboardkeyboard input

How does Input.anyKey work?

How does Input.anyKey work? does it check a single value, or go through and check every key?

Given I have the following script:

     if(Input.anyKey) {
         if (Input.GetKeyDown (KeyCode.LeftArrow)) {

         } else if (Input.GetKeyDown (KeyCode.RightArrow)) {

         } else if (Input.GetKeyDown (KeyCode.UpArrow)) {

         } else if (Input.GetKeyDown (KeyCode.DownArrow)) {

         }
     }

If it checks a single value then it will be more efficient to group my button checks under its single if statement, however, if it checks every button (not just the few I need to check) then it will be more efficient without it.

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 meat5000 ♦ · Mar 19, 2018 at 12:21 AM 0
Share

I think the way you use it there is an unnecessary step. It does nothing in your case.

avatar image Bunny83 meat5000 ♦ · Mar 19, 2018 at 01:15 AM 0
Share

Well, he wants to avoid the checking of each Input.Get$$anonymous$$eyDown if there's no key pressed at the moment. However since we don't know how exactly any$$anonymous$$ey is implemented we can't tell if this is actually an improvement or not. Of course considering just those 4 keys it's absolutely pointless to do this extra step. It might get interesting if you have 20, 30 or more such if statements.


However in such a case i would rather go with events anyway (using OnGUI or Event.PopEvent). Though be careful with Event.PopEvent. This method will actually remove the event from the queue. The new UI system relies on this method. So when calling it unconditionally every frame you basically prevent the UI system from working normally. OnGUI would be the better solution.

avatar image meat5000 ♦ Bunny83 · Mar 19, 2018 at 09:49 AM 0
Share

i imagine any$$anonymous$$ey to be a flag raised by the occurence of an event. It'd be totally silly if it iterated all possiblities.

You mentioned a while back that there is some loop/branch in which the contents of the Braces are evaluated anyway whether the condition was correct or not. Was this an if statement or a for loop?

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

91 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

Related Questions

Input keys not working ! please help me,Can't use input keys ! please help me ! 0 Answers

Is it possible to get input from bluetooth keyboard on iOS? 0 Answers

How to get the keyboard to work with Voice Over on iOS? 0 Answers

Rebind - Excluding Certain Keys 0 Answers

Custom keyboard layout for mobile game. 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