Ignore mouse click outside of the UI
Hey all, I am having a problem with my in game UI menus like the pause menu.
When I hit the escape key the mouse cursor and pause UI is shown with 2 buttons "Continue" and "Exit". I have locked the player from moving when this UI is shown. But when I click outside of the buttons the mouse disappears and the player can move once again, the UI is still shown but it's lost focus or something.
Is there a simple way to stop this? I've seen some scripts which seem to try to catch this behavior and ignore the click but I'm hoping there is a property on the canvas or something that I can use built into the engine.
Thanks, Sam
Add a panel behind all UI objects and make it invisible. Easy and fast solution probably not optimum. Cheers
There is currently a smallish panel around the buttons and when I click that I still get the same behavior as explained in my question.
Do you use the Unity Standard assets fps controller? or any same kind of mouse lock?
I tried making a full screen panel with raycast turned on and I still have the same behavior.
I found it! There is a Input.Get$$anonymous$$ouseButtonUp(0) call in the camera code, hadn't found it before because I search for all Get$$anonymous$$ouseDown calls. Thanks dude, you helped me track that one down!
Answer by Manumoi · May 19, 2017 at 03:35 PM
If I correctly understand your issue, just create an additional panel to your UI with anchors set to cover the whole screen as a background to your UI buttons (buttons have to be above this panel).You can then make its image component transparent (or semi transparent) but make sure its raycast target property is set to true.
Your answer
Follow this Question
Related Questions
is there a way to detect OnMouseDown on a UI image? 2 Answers
How do i move a canvas? 0 Answers
changing the UI controls from mouse to key 0 Answers
Pause menu not called when ESC pressed 2 Answers
Event on mouse up 2 Answers