- Home /
Put mouse to sleep
I'm trying to create a UI for the main menu that can use mouse or arrow buttons to select the new, load, option buttons etc.
Both are working fine, however I want to disable the mouse once a key is pushed, and remain disabled until it is moved again. Currently if the mouse is over a button and I push the down key, the option will not be able to change as the mouse is still hovering over the first option
Is there a way to put the mouse "to sleep" once these buttons are pushed, and then wake when it is moved again?
Answer by Oninji · Dec 13, 2011 at 05:54 AM
Well the simple way would be to have a boolean that keep track of when or not the mouse should be used. Then put a if(!mouseEnabled){ //Your mouse react to button code here. }
So that your buttons do not react to your mice.
I couldn't get this to work for my situation because when the mouse is disabled it will still act as the highlighted button. I wan't it to be as if the mouse disappeared and is no longer interacting with it
A temporary fix I can think of is when the up, down button is pressed the mouse moves to 0,0 and when the mouse is touched again it moves back to where it was. That sort of explains it acting as if it were not on the object, but surely there is a more professional way to achieve this :P
Well, you could lock the mouse to screen and when the condition "mouseEnabled" is false, set the texture of the mouse to a transparent one.
Your answer
Follow this Question
Related Questions
How can I disable gamepad input, for my UI? 1 Answer
Prevent raycast to OnMouseOver() or OnMouseEnter() when mouse over UI 1 Answer
Unity UI Mouse + Keyboard navigate, Un-Highlight button choice on mouse over 0 Answers
(4.6 UI) How to highlight a character/unit when moused over? 1 Answer
Trouble with unlocking cursor 1 Answer