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 milanow · Dec 08, 2014 at 06:50 PM · uiinteractionhighlight

4.6 New UI System, how to detect if a button is selected

Hi, I want to drop mouse control in a scene and instead using keyboard completely to interact with UI part in the scene. So as you know when mouse is over a button, a default button in version 4.6 would highlight to show it is focused. However, for now I only have keyboard input, could I click a button by pressing a key (like Enter) and choosing which button is focused (like using Up or Down arrow).

I have implemented the part that pressing a key to call OnClick function of a certain button by EventSystem. But I don't know how to detect if it is highlighted to show it's the target interactive UI part (like a mouse on it).

Thanks in advance.

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
1

Answer by fafase · Dec 08, 2014 at 07:08 PM

Well, using keyboard is just the same as mouse, you define the navigation either automatic or you make it yourself. Then it works.

The main issue is setting the original button. Without any code, you need to trigger one with mouse and then you can navigate (at least for what I have seen).

By code you can set which is the default one:

 public class NewBehaviourScript : MonoBehaviour 
 {
     [SerializeField] private GameObject defaultButton;
 
     void Start()
     {
          EventSystem.current.SetSelectedGameObject(defaultButton, null);
     }
 }

It works but I can't explain why the first move requires two clicks. Maybe someone has a totally working solution.

Comment
Add comment · Show 2 · 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 milanow · Dec 09, 2014 at 03:04 AM 0
Share

Oh yeah that makes sense, I think it will work fine, thanks!

avatar image losingisfun · Nov 14, 2017 at 06:11 AM 1
Share

for some weird reason if it's not in the Start() $$anonymous$$ethod, it selects, but doesn't highlight. You can work around it like so:

 defaultButton.Select();
 defaultButton.OnSelect(null);

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity3d 4.6 GUI Buttons Interaction Broken after Maximizing Window 0 Answers

Dragging objects like in Amnesia 2 Answers

Prevent rigidbody interaction 1 Answer

RPG Text 2D on Object Interaction Javascript 0 Answers

Interacting with gameobjects of same tag 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