0
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ Have you tried to add a transparent image behind your pause menu, filling your whole screen, with raycast target property enabled ? \$\endgroup\$ – Hellium Apr 27 '17 at 13:28
  • \$\begingroup\$ @Helloium Yes I have tried this. Doesn't change the behavior. \$\endgroup\$ – SamJ Apr 28 '17 at 13:04
5
\$\begingroup\$

Easiest way to handle this is to make a transparent background for your UI and let it catch the raycasts (if you're using them) or the mouse clicks so that the main game doesn't gain the focus of the program.

Another way would be to put an if on the mouse script you're using and reset focus to the UI after a click is made on anywhere but the UI (this will mean that the mouse will disappear momentarily and the player might be able to control stuff if you didn't do your pause checks properly).

I'd suggest using the first method. You could even add a blur effect (if you can manage to do it properly) to the layer of that background and give a more menu-like feeling. (this part is harder than it sounds)

\$\endgroup\$
  • \$\begingroup\$ Thank you John, I actually like the idea of the slight blur to make it more menu like. I will give this a go and let you know how it goes (by marking this as the answer :)) \$\endgroup\$ – SamJ Apr 28 '17 at 1:12
  • \$\begingroup\$ Doesn't seem to work for me. I place a panel that fills the whole screen and when I click outside the buttons it still returns the focus to the scene but has the UI shown still. \$\endgroup\$ – SamJ Apr 28 '17 at 13:03
  • \$\begingroup\$ @SamJ Are you sure you put something that catches the mouse clicks? Relevant: gamedev.stackexchange.com/questions/133923/… \$\endgroup\$ – John Hamilton Apr 28 '17 at 19:58
  • \$\begingroup\$ sorry, I haven't had much time to look at this over the weekend. The only thing I could think of that might be catching the mouse click is the code in the camera script but I don't think it is, I will check tonight. FYI I double checked that building and running had the same behavior and it does. \$\endgroup\$ – SamJ May 1 '17 at 2:50
  • 1
    \$\begingroup\$ I found it, I had a pesky Input.GetMouseButtonUp(0) in my camera code that I hadn't found on my searching for GetMouseButtonDown search. Thanks for all your help man :) \$\endgroup\$ – SamJ May 1 '17 at 9:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.