Call OnMouseDown on second collider when three overlap.

So I’m having the problem that three BoxColliders2D overlap.
I want to call the OnMouseDown function from the middle collider, but another one is in front of this one.
changing the z-value isn’t an option, because I also do need the OnMouseDrag from the upper collider.
The middle collider isn’t always the same object with the same script. Or else I would just do a distance check, get the script and call “OnMouseDown”.
The collider all the way in the back can be totally ignored.

So long story short: how to play the OnMouseDown, while another collider is in the way?

You should probably just create your own raycaster script and use RaycastAll to get all the colliders and call the method you need from any of the resulting hits.

1 Like