- Home /
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.
Answer by Ashkan_gc · May 29, 2010 at 10:49 AM
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.
Answer by spinaljack · Apr 23, 2010 at 01:13 PM
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.
The first doesn't help with the onmousedown issue and the layer masks will ignore the object entirely ins$$anonymous$$d of ignoring some of its colliders. I understand I can use a raycast and loop through the colliders but this would require completely re-working the selection system that was previously in place. I was wondering if there was a solution that would allow me to still use the onmousedown method. I apologize if that wasn't clear originally.
Thanks. I've been struggling for long with it. I have a transparten ceiling (i.e. a GameObject with only a collider) and the camera is above it, The on$$anonymous$$oueDown of the gameobjects below the ceiling weren't called but by using "Layer: Ignore Raycast" everything works perfect
Answer by Talmagett_Games · Feb 24, 2021 at 07:58 PM
It worked for me, i just changed Z axis of one object