object with multiple colliders ignoring mousedown for some.

I currently have a select system using onmousedown. I added colliders to units to keep track of what is in their viewing range. The problem is I can no longer select the buildings behind the unit but select the unit instead.

So the question is, How can I get the extra colliders to be ignored by mousedown but still allow the main, original collider to be clickable.

When you use a raycast you can get a list of all colliders that it passes through, simply loop through the list until you find what you need, for this you can use if else statements to form rudimentary selection priority. You can also use layer masks to ignore specifically colliers used for sight range.

Docs

there is not any way to do what you want. OnMouseDown uses all colliders so the collider that is near will effect your selection. you should either change the selection code or your other part of logic that uses multiple colliders.

It worked for me, i just changed Z axis of one object