How to check if object is clicked? (unity 2d)

175 Views Asked by At

I used method below to check if button(object) is clicked. The problem is that I have a Confiner which is streched over the entire level and as a result method determine this Confiner but not the object that I need. So the question is can I somehow ignore confiner and only check if I clicked an object?

void OnMouseDown()
    {
       ....
    }
1

There are 1 best solutions below

0
zambari On

Implement IPointerClickHandler interface (from UnityEngine.EventSystems). This also works for 3d objects if your camera has PhysicsRaycaster component