To disable mouse input, open the InputManager from Edit > Project Settings > Input. Remove the input entries with Mouse in their name. Expand Fire1 - Fire3 and remove the mouse buttons from these. To hide the cursor, use the statements:
Hey.
I had a similar issue and this worked for me. If there’s any mouse clicks it just goes back to the default selection.
If you stored your current selection in a variable you could always use that as a parameter: CatchMouseClicks(currentButton);
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
{
CatchMouseClicks(defaultSelection);
}
}
public void CatchMouseClicks(GameObject setSelection)
{
EventSystem.current.SetSelectedGameObject(setSelection);
}
A bit late, but I just found this as I was trying to do the same.
What I did was have a GO (named MouseDisable) with a UI Image on it that stretches across the whole screen, and has ‘Raycast Target’ ticked. Also, make the Color white, and with Alpha = 0. IE not visible.
Then when ever I change the Cursor.visible, I just enable/disable that GO, and it ‘absorbs’ all the mouse clicks.
So, something like:
public void SetCursorVisible(bool vis) {
Cursor.visible = vis;
MouseDisable.SetActive(!vis);
}
The StandaloneInputModule is the code that sends mouse events and also converts keyboard events into selected/focused objects into Unity’s Canvas UI system.
You can disable this module which will prevent sending over the mouse and keyboard button events to the canvas.
If you want to disable just the mouse, you can make a new class to override the StandaloneInputModule, Override the ‘process’ function and just do this:
public override void Process()
{
bool selectedObject = this.SendUpdateEventToSelectedObject();
if (this.eventSystem.sendNavigationEvents)
{
if (!selectedObject)
selectedObject |= this.SendMoveEventToSelectedObject();
if (!selectedObject)
this.SendSubmitEventToSelectedObject();
}
//this.ProcessMouseEvent();
}