🖱🎯 Mouse Navigation Support
🔥
2
❤️
2
This add-on will enable mouse support for your game! After following these instructions, all your menus should be usable with a mouse! Simply hover an element to select it, and use a “Left Click” to interact!
- Find your
PlayerInputActionsasset in your project (it should by default be under: Assets/Mythril2D/Demo/Settings/PlayerInputActions.inputactions) - Click on the
PlayerInputActionsasset => your inspector should now display a button “Edit Asset”. - Hit the “Edit Asset” button
- In the newly opened window (Input Actions), click on the “All Control Schemes” dropdown menu, and select “Keyboard”
- Click on the “All Control Schemes” dropdown menu again, and this time select “Edit Control Scheme…”
- Click the
+button, and add “Mouse” as a device type. You should now have 2 device types:<Keyboard>, and<Mouse>. Additionally, you can rename the “Scheme Name” from “Keyboard” to “Keyboard&Mouse” - Save the changes to the control scheme.
- Under “Action Maps”, select UI
- Right click on the “Submit” action, and select “Add Binding”: a new binding should have been created:
<No Binding> {GLOBAL} - Edit the newly created binding, by setting its “Path” to “Mouse > Left Button”
- Under the “Use in control scheme” label, select “Keyboard” (or “Keyboard&Mouse” if you renamed the control scheme)
- Back to the “Actions” panel, right click anywhere in the blank space under “Skip” to create a new action with the “Add Action” button. Name this new action “Point”
- Set the “Point” action “Action Type” to “Pass Through”, and the “Control Type” to “Vector 2”.
- Expand the “Point” action with the ▶️ icon to the left of its name
- Select the empty binding:
<No Binding> {GLOBAL} - Set its “Path” to “Mouse > Position”
- Check the “Keyboard” (or “Keyboard&Mouse”) checkbox under the “Use in control scheme” label
- Hit the “Save Asset” button at the top right of the current window.
- Open the “Main Menu” scene (Assets/Mythril2D/Demo/Scenes/Main Menu.unity)
- Type
t:InputSystemUIInputModulein the hierarchy search bar. - Select the GameObject that shows up, and find its “Input System UI Input Module” component in the inspector.
- Set the “Point” action to use “UI/Point”
- Save the scene
- Open the “Gameplay” scene (Assets/Mythril2D/Demo/Scenes/Gameplay.unity) and repeat steps 20 to 23
- Open the
InputSystem.csscript (Assets/Mythril2D/Core/Runtime/Scripts/Game/Systems/InputSystem.cs), and add this function anywhere inside of theInputSystemclass:
private void Update()
{
InputAction pointAction = playerInput.actions.FindActionMap("UI").FindAction("Point");
if (pointAction.ReadValue<Vector2>() != Vector2.zero)
{
var eventSystem = UnityEngine.EventSystems.EventSystem.current;
if (eventSystem.IsPointerOverGameObject())
{
var pointerEventData = new UnityEngine.EventSystems.PointerEventData(eventSystem)
{
position = Mouse.current.position.ReadValue()
};
var results = new System.Collections.Generic.List<UnityEngine.EventSystems.RaycastResult>();
eventSystem.RaycastAll(pointerEventData, results);
foreach (var result in results)
{
var selectable = result.gameObject.GetComponentInParent<UnityEngine.UI.Selectable>();
if (selectable != null)
{
eventSystem.SetSelectedGameObject(selectable.gameObject);
return;
}
}
}
}
}
- Save the file
- Hit play, and enjoy!
Optional: You can push mouse integration further by adding additional bindings in your “Gameplay” and “UI” action maps, under actions like “Interact”, “FireAbilityX”, “Skip”, and “Cancel”

💬 Comments (4)
There are several assets that can add that feature to your game, like this one: https://prf.hn/click/camref:1100l3L8uv/destination:https://assetstore.unity.com/packages/tools/gui/settings-game-options-unified-menu-240015
Otherwise it should be fairly easy to implement and make it work with any games, as Unity’s new input system (which is what Mythril2D uses) is very permissive
Want to continue the conversation?