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
0
Question by Ochreous · Jun 03, 2013 at 12:16 AM · c#hotkeys

C# Creating Hotkeys

Hi everyone, I'm trying to make a hotkey script that allows me to assign hotkeys. But I'm not sure how. How do you figure out which key was assigned as a hotkey and how do create an if statement that checks whether or not that key was pressed?

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

Answer by randomuser · Jun 03, 2013 at 12:50 AM

First, make sure you extend from editor and not monobehavior.

Second, here is a example on exactally on what you are talking about. http://wiki.unity3d.com/index.php/Blender_Camera_Controls

If you still need help after looking at this example then send a comment and I will explain it in more detail.

Comment
Add comment · Show 5 · 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 Ochreous · Jun 03, 2013 at 04:56 AM 0
Share

I was think more on the lines of Diablo 2 hotkeys. This is just one switch statement. I want to actually assign which hotkeys I can use.

avatar image syclamoth · Jun 03, 2013 at 05:24 AM 0
Share

You're talking about something in-game, right? So an editor script is useless to you. The switch statement is spot-on, though- all you need to do is put that in 'OnGUI' and switch over 'Event.current.keyCode'. If you wanted them to be customisable, you could easily ask the player to press a key, then record the next pressed keyCode as the new hotkey.

avatar image Loius · Jun 03, 2013 at 05:28 AM 1
Share

There are custom input managers on the Asset Store, most of which will handle hotkeying for you. I probably wrote one of them :)

It's easiest to store keys as $$anonymous$$eyCode values:

 if ( listeningForInput && Event.current.keyCode != $$anonymous$$eyCode.None ) {
   listeningHot$$anonymous$$ey = Event.current.keyCode;
 }

avatar image Ochreous · Jun 03, 2013 at 05:29 AM 0
Share

Yes but how do I detect which key was pressed? With a for loop maybe?

avatar image syclamoth · Jun 03, 2013 at 05:36 AM 0
Share

You're not listening. In 'OnGUI', you can do this:

 if(Event.current.is$$anonymous$$ey) {
     key = Event.current.keyCode;
 }

In case it wasn't clear, almost all of the Unity editor was implemented with the very GUI functions you have available to you in-game- which means that most things they can do, you can do.

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

17 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

Related Questions

C# How to Detect Edges of a Collider 0 Answers

FPS keep a loadout 0 Answers

C# Number Key For Loop 1 Answer

C# GUI.Tooltip If Statement 2 Answers

C# SetActive GameObject Array 2 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