I have a UI message box that waits for a user to click OK to continue. But for some reason, if a gameobject with a collider on it is behind it, it will run that code when “OK” is clicked. Is there any way to stop colliders from working in the scene if a UI object is interacted with?
I’m doing it through code by setting variables on the different scripts for each UI object with a “isShowing” public variable that I set to true and false, but was hoping there was an easier way to do it.
If the game behind queries the mouse directly then you need to do the boolean approach above, or an equivalent.
You can trivially drop an “input inhibitor” script on every popup UI item and as long as the UI is present, the input is inhibited. Here’s an example:
I prefer lots of tiny generic scripts like the above, rather than sprinkling specialized code all over!
If the game behind the message box is all UI-clicky stuff, you don’t need the above: just put an invisible fullscreen blocker up as part of your UI message box and then no clicks will get through. This can be helpful:
https://answers.unity.com/questions/801928/46-ui-making-a-button-transparent.html?childToView=851816