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 charline · Jun 17, 2011 at 10:26 AM · guikeyboard

GUI controlled by keyboard

Hello!

My question is very simple. I have a GUI button "Play" and I want the player to be able to press it by hitting a key (and not using the mouse). There are no other options-there is only one button and the player will hit it.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cocopuffs · Jun 17, 2011 at 11:20 AM

well i was thinking cant you just add inputs???? and trough a script define that when input spacebar is pressed set GUI awake :) well thats what i would do im not shure if thats the best or the right way to do it but i gess its something:)...i would help you with the script but i still havent mastered scripting:(....ohhh the imput menu is in Edit--->ProjectSetings-->input

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 cocopuffs · Jun 17, 2011 at 12:07 PM 0
Share

ok for the method i told you to ...go into input then for the "size" add one....so for my current input it displays 21 for size ...so i would make it 22....then you will see a new input appear at the bottom of the list .....(you know its new because its a duplicate of the one ontop of it......change the name of the input to whatever you want(make shure you remember)i put Button1...click on the input and find "positive Button"...click on that and press the spacebar(or the key you want to activate the GUI with),ok now make a new java and type something like this http://pastebin.com/Fh1j$$anonymous$$B$$anonymous$$J then you type what you want the space bar to do when pressed.....i dont know the exact code but i would gess some thing withon trigger and with awake....well im sorry i cant help you any further im not that good at scripting...im bearly learning :)

avatar image
0

Answer by Anxo · Jun 17, 2011 at 11:27 AM

you can make a label look like a button with gui styles, then in the update function have a if key down command.

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
avatar image
0

Answer by Bunny83 · Jun 17, 2011 at 12:21 PM

I guess you're using UnityScript?

 function OnGUI()
 {
     var e = Event.current;
     if (GUILayout.Button("Play") || (e.type == EventType.KeyDown && e.keyCode == KeyCode.Return))
     {
         // Start the game
     }
 }

If you want any key to start the game just remove the keycode check ;)

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
avatar image
0

Answer by charline · Jul 12, 2011 at 03:18 PM

Thank you all very much!

Bunny83 your comment was so straightforward and easy to implement. Thanks again.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to Select a Focus Control? 1 Answer

Issue with GUI.TextArea keyboard on iPhone 0 Answers

Controlling Pause Menu with Keyboard 2 Answers

Assign keystrokes to GUI button 2 Answers

How to get a button to act as a keyboard key 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