How to Click a GameObject inside an invisible trigger box

I’ve got an object inside of an invisible “wind” box that applies a constant force. In order to control the object you have to be able to click on it, but the mouseclick on the object is not registering because the ray is colliding first with the invisible trigger box. Any thoughts?


The typical solution is to put the clickable object on a different layer. Then you use the mask parameter available in some versions of Raycast() to only cast against the object that are clickable.

A less efficient solutions is to use RaycastAll() and then sort through the hits returned to see if it is one of your clickable objects.

Use a LayerMask. Assign the object to be controlled to a layer different from the wind and make your raycast ignore the wind’s layer. It’s easy to include and exclude layers in the Inspector with a public LayerMask variable, but if you want to set it manually, read Stelimar’s and Statement’s explanations on bitshifting.