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 belamessex · Mar 18, 2016 at 08:35 PM · guiinputeventsystem

Send UI Button Event with key press NOT onClick()???

Hi, I've got a simple start menu with "Start" and "quit" buttons. I've already set up navigation between them with Horizontal axis using the EventSystem, but I have no idea how to get either of my buttons to call a method in my ManagerScript using Enter or Space keys. I know how to do this using the "OnClick()" on the button component, but I would like to have no mouse, only keyboard inputs. There are plenty of games that use gamepad or keyboard to send events via UI, so I feel like it's probably really simple. So how would I go about that tho?

Thanks!!!

Comment
Add comment · Show 2
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 MechanicalGaming · Mar 18, 2016 at 08:44 PM 0
Share

$$anonymous$$ind posting some of your code? The code with the Button commands would be what I will need

avatar image belamessex MechanicalGaming · Mar 19, 2016 at 01:45 AM 0
Share

i think it got answered

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by flashframe · Mar 18, 2016 at 09:31 PM

In the Standalone Input Module component of the Event System game object in your scene, you can specify which keyboard/joystick inputs to use for Submit and Cancel on your UI. (You set these buttons up in Edit/ProjectSettings/Input)

alt text

Then on your button, add an Event Trigger for Submitalt text


event-trigger.png (89.0 kB)
inputmodule.png (26.0 kB)
Comment
Add comment · Show 3 · 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 belamessex · Mar 19, 2016 at 01:43 AM 0
Share

hey thanks for this. I had no idea that you could add an event type to a button. this is what i was looking for.

avatar image KarlKarl2000 · Mar 18, 2018 at 09:36 PM 0
Share

@flashframe

You sir are a coding god!

This UI challenge was bugging me for a couple years. I had left it on the backburner until this week, which I was deter$$anonymous$$ed to figure out how to get a simple Unity Grid Layout Group to respond to keyboard input. After banging my head reading so many useless threads with long nonsensical , convoluted solutions, I found this short and simple answer.

This was the answer I was looking for. Thank you!

Sharin' is carin'

@indieDoroid

avatar image TooManySugar · Jul 26, 2018 at 10:04 AM 0
Share

So, is it possible/safe to have like A and B buttons mapped so Submit? In the Standalon Input $$anonymous$$odule I see option to only add one button, may be is it possible to add more like Button1;Button2? or in the Edit/ProjectSettings/Input Should we have two "Submit" named inputs and in the Standalon Input module Submit Button have "Submit" assinged?. That is correct way to do the things?

avatar image
0

Answer by Dudicus · Mar 18, 2016 at 09:29 PM

Use:

 void Update () {
         if (Input.GetKeyDown("Enter"))
         {
                 Application.Quit();
         }
 }

This would be for the quit button. For the Start button replace Application.Quit(); with whatever variable or method you are using to start the game.

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 belamessex · Mar 19, 2016 at 01:41 AM 0
Share

i'm not sure this would work. As long as the quit button is enabled, escape would cause the game to quit, regardless of the button highlighted. I'm trying to use one button input or a "submit" button.

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

66 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

Related Questions

World space GUI interaction with just a crosshair and a keyboard 0 Answers

GraphicRaycaster UI event issue with Unity v5.2.0bx 1 Answer

Changing the Standalone Input Manager variables 2 Answers

Trigger an event from editor script? 0 Answers

Input not registering while TextField is selected 3 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