Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Jan 20, 2021 at 04:55 PM by LenaWi for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by LenaWi · Jan 20, 2021 at 04:11 PM · uibuttonsnavigation

How to navigate through UI buttons without keyboard arrows?

Hi all,

I have some buttons in a UI canvas. The navigation through the UI works fine with the keyboard Arrows.

Now i am trying to handle the navigation with another Input device, that cannot be recognized by Unity automatically. So i just have a boolean that becomes true if i click "Up" or "Right" with this device.

Is it possible to call the same navigation / move -function like the Left/Right/Up/Down Arrows on the keyboard but just for a boolean input?

So what i want is:

 if (Device.boolUp == true)
 {
 //navigate left in UI
 }

and so on for Left / Right / Down. Thanks for your Help!

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

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by LenaWi · Jan 20, 2021 at 04:31 PM

@IBXCODECAT Thanks for your answer!

By chance i found this code:

 EventSystem.current.SetSelectedGameObject(button.FindSelectableOnDown().gameObject);

I think this FindSelectableOnDown() is what i was searching for. So probably when i first ask for the actually selected button and then tell the system to select the down button it could hopefully work.

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 IBXCODECAT · Jan 20, 2021 at 04:33 PM 1
Share

Welcome, and good luck!

avatar image
0

Answer by IBXCODECAT · Jan 20, 2021 at 04:19 PM

Unity uses the event system (that is automatically created when creating UI or a canvas.) In the event system there should be references to input axis. Try changing the axis. Unfortunately you can not do this through code, if you want this to work at run-time try making your own input manager.

 public static class GameInputManager
 {
     static Dictionary<string, KeyCode> keyMapping;
     static string[] keyMaps = new string[6]
     {
         "Attack",
         "Block",
         "Forward",
         "Backward",
         "Left",
         "Right"
     };
     static KeyCode[] defaults = new KeyCode[6]
     {
         KeyCode.Q,
         KeyCode.E,
         KeyCode.W,
         KeyCode.S,
         KeyCode.A,
         KeyCode.D
     };
  
     static GameInputManager()
     {
         InitializeDictionary();
     }
  
     private static void InitializeDictionary()
     {
         keyMapping = new Dictionary<string, KeyCode>();
         for(int i=0;i<keyMaps.Length;++i)
         {
             keyMapping.Add(keyMaps[i], defaults[i]);
         }
     }
  
     public static void SetKeyMap(string keyMap,KeyCode key)
     {
         if (!keyMapping.ContainsKey(keyMap))
             throw new ArgumentException("Invalid KeyMap in SetKeyMap: " + keyMap);
         keyMapping[keyMap] = key;
     }
  
     public static bool GetKeyDown(string keyMap)
     {
         return Input.GetKeyDown(keyMapping[keyMap]);
     }
 }
  

You could use it like this:

 void Update()
 {
       if (GameInputManager.GetKeyDown("attack"))
       {
             //Do stuff
       }
 }

instead of this:

 if(Input.GetKeyDown(Keycode.W)
 {
      //Do Stuff
 }
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 IBXCODECAT · Jan 20, 2021 at 04:32 PM 0
Share

Do stuff would be what you wanted to happen when you gave the input

avatar image
0

Answer by IBXCODECAT · Jan 20, 2021 at 04:22 PM

Also you could create multiple 'inputs' in the default input manager and switch between them.

 switch(inputMethod)
 {
     case 1:
         //Use axis 1
         break;
     case 2:
         //Use axis 2
         break;
     case 3:
         //Use axis 3
         break;
      default:
         //Axis invalid
 }
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

Follow this Question

Answers Answers and Comments

194 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 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 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

Setting a button navigation mode throug code 1 Answer

Input Fields - Navigating with tab 1 Answer

A button inside of a button is highlighting parent button 1 Answer

UI: Tooltip for multiple images behind bigger button? 1 Answer

UI not working after build 0 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