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
1
Question by N1warhead · Mar 07, 2016 at 05:25 AM · getkeydowngetkeygetkeyup

Input.GetKey question

Okay I'm going to attempt to ask this question again, does Input.GetKeyDown(KeyCode.F)){ } work on all 3 (Windows, Mac and Linux) or is there some other way I have to do this between each platform?

This is the third time trying to ask for help and I really urgently need to know as I seriously can not whatsoever find anything online about it, and being I don't own a Mac or Linux to test this I have no other way of finding out.

Thanks.

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
2

Answer by JoshuaMcKenzie · Mar 07, 2016 at 07:32 AM

For this specific set up, yes. The Input class entire purpose is to give cross-platform support while minimizing the impact to your code. So for all standalones, this will work just fine.

There are some cross-platform caveats tho with this specific line of code. GetKeyDown will only work for standalones (unsure if it works for mobile keyboards but then again its a bad idea to rely on a those for most mobile games). Also this is hard-coding the hotkey which disallows the player from changing their key setup.

Instead to provide easily configurable and fully cross-platform support you should fill out the Input Manager (Edit>Project Settings>Input) with the input slots relevant to your game. so lets say that you were using "F" to open inventory before, you'd then create an input slot named "Open Inventory" with the "F" key mapped to it. but now you can also map a joystick setup to it as well so that you could use an XBox controller to open the inventory via the "x" button.

From here instead of using Input.GetKeyDown(KeyCode.F) which is hard-coded and works only for keyboard events, you use Input.GetButtonDown("Open Inventory") and that will work on all platforms, keyboard or mouse, and even plug-in controllers (xbox, playstation, or whatever). The player can choose to map the hotkeys around to their liking.

the getButton functions can really minimize the amount of code you have to check for since you can actually map multiple hotkeys to the same input slot ( for example, in my game I remapped horizontal and vertical to both wasd and the arrow keys).

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

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

36 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

Related Questions

Can/how do I set up a boolean to continue an animation after button press 1 Answer

Dialogue with GetKey - Codes 1 Answer

Change view if key is pressed 4 Answers

Update GetKey If Statements both playing instantly 1 Answer

GetKey/GetKeyDown, Paired with Adjusting Stats 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