- Home /
How to pass a pointerclick event on to the next collider ?
I have multiple 2d box colliders on top of each other. I use the iPointerClickHandler interface to intercept the click and this works fine. The object that is render on top of the other will receive the OnPointerClick call.
But my question is then, can I ignore, or when I am finished with the event let the next Collider in line to have it instead ?
I am trying to create a debug mode in a game so that on top of every click that happens I want to display some information about the current action that was taken, and this includes clicking on things that dont have any regular effect inside the game.
I solved it by making my own touch handling using raycasting.
Answer by slake_it · Sep 26, 2015 at 05:55 PM
@seth_slax i think you can use Physics.RaycastAll to get all the intercepted objects instead of performing a raycast multiple times, however, i don't know what is the order they are retrieved in.
Totally forgot RaycastAll existed @slake_it, haha. If the order was out, you could simply sort it based on Vector3.Distance of the raycast origin.
Answer by seth_slax · Sep 25, 2015 at 09:38 AM
Just change the LayerMask of the clicked object to the IgnoreRaycast layer in code, or create your own custom RayMask and switch to that.
What I wanted was a way to decide in code WHEN clicked if the collider should "sawllow" the click or pass it along so that the click could actually pass through all the colliders that was hit.
I don't think there's a way to recieve a raycast and continue it along. The only alternatives I can think of would be (psuedocode):
Fire raycast.
Object hit decides to absorb or ignore.
If ignore, call another raycast from the original source.
Repeat for each collider (or just have duplicate scripts).
Or:
Fire raycast.
Object hit decides to absorb or ignore.
If ignore, switch layermask to IgnoreRaycast.
Fire a raycast from the hit.point of the collider onwards.
Repeat accordingly.
I ended up using the
public static RaycastHit[] RaycastAll(Ray ray, float maxDistance = $$anonymous$$athf.Infinity, int layer$$anonymous$$ask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
that fills an array of all the hits that I could use the way I needed.
Your answer
