- Home /
is it Possible to use navigation on non UI elements?
Hello there,
my question is, is it Possible to use navigation on non UI elements, if so how? I'm trying to navigate through objects in the world (2D btw) with arrow keys, like you would do with buttons on UI, just to simply traverse through them. maybe have OnEnter, OnClick... on them.
I made the gameobjects have a button which gave them the navigation lines but with no responsive. I'm sure there is a better way to do that rather than adding a button to gameobjects that are in the world and aren't on the UI.
Thank You for your time:)
Answer by Xarbrough · Dec 18, 2020 at 10:58 PM
On your selectable GameObjects, you put a script that implements ISelectHandler, either a custom class that implements the interface or something like the Unity EventTrigger component. Then you need an EventSystem and drag the first selectable GameObject into the "first selected" field. Now the GameObject becomes selected. If you now want to add navigation, you could subclass Selectable, which would automatically give you the same options that the Button is using, but it's also possible to implement the individual callbacks yourself (IMoveHandler for example to handle the arrow keys).