Home > Net >  Unity OnMouseUp() triggered when object is covered bu UI element
Unity OnMouseUp() triggered when object is covered bu UI element

Time:11-29

I have got some 2D elements in my scene with CircleCollider2D on them and a script with onm ouseUp(). At some stage a UI panel is rendered over the objects, and when I press a button that happens to be above the element with the onm ouseUp() it triggers both. I want to avoid disabling the circle collider every time the panel shows up and then enabling it after because of some other functionality. What can I do? Do I have to use raycasting?

Thanks for all help in advance.

CodePudding user response:

The onm ouseButton() does not answer objects in the Ignore raycast layer, so change the layer between those will solve your problem, another approach is to make an event when you open and close your menu and a bool field in your character like IsClickable, then you just toggle it as the answer to UI open/close event. Hope this helps

CodePudding user response:

You can check if the cursor is over UI. You can do this with the EventSystem.IsPointerOverGameObject() method, which returns a boolean. The documentation for the method.

  • Related