Best way to block clicks on certain part of screen?

I Want to disable left clicks in a certain script when the mouse is over the lower part of the screen. The UI part on the bottom of this image.


I’ve tried attaching a script to the image to do it when the mouse is over, which kind of works, but if I go over one of the other images, it doesn’t detect it. All the smaller images are separate UI objects that are enabled when selecting different game objects. I tried to run a ray to detect if the mouse was over any image, but it doesn’t seem to work at all.

All I need to do is have a certain part of a script that handles unit movement to bypass left clicking as long as I am mouse over the lower menu part of the screen. Just looking for ideas. Thanks.

You’d need to poll your mouse position every frame and set a bool like isOverMenu. If it’s true, then a condition in your unit movement script will disallow the default actions.
Your shapes at bottom are simple boxes, so you can use a rect bounds kind of check quite easily.

You can’t block the click itself afaik, you can only ignore it.

do you know about EventSystem.current.IsPointerOverGameObject ? that what I use to differentiate “game” clicks from UI clicks

you can just stick a transparent rect over there to block the UI

1 Like

Right, that’s what I mean. I plan on enabling a bool on my script and having it not perform the function on click if the bool is true, which would mean over my UI.