RaycastResult - Any way to make it ignore objects?
I'm using RaycastResult, which is sent to OnPointerUp/OnPointerDown event handlers to detect clicks on a mesh. The scene contains a second mesh that I use as water. I'm trying to get it to work in such a way that I can click on the mesh in the water. Unfortunately, the water mesh is getting in the way.
So far I've tried setting the water layer to "Ignore Raycast" but that doesn't seem to work with RaycastResult - I'm guessing it's RaycastHit only.
At the moment, the only thing that seems to be working is to turn off the water's Mesh Collider. The problem with that is that I want it to be a trigger so that I can have a different sound when the player's sloshing around in the water.
public void OnPointerDown(PointerEventData eventData)
{
currentPointerTimer = 0;
pointerHeldDown = true;
pointerEventData = eventData;
}
In my OnPointerUp, I have this:
RaycastResult hit = eventData.pointerPressRaycast;
Vector3 p = hit.worldPosition;
And in my Update, I have this:
RaycastResult hit = pointerEventData.pointerPressRaycast;
Vector3 p = hit.worldPosition;
It all works perfectly except for the fact that the water's Mesh Collider gets in the way when I'm trying to click on something in the water.
Answer by FortisVenaliter · Aug 31, 2017 at 09:03 PM
Work with the layers. Set the water to it's own layer. I haven't used those event raycasts like you are, but every raycast function I've used takes in a layer mask as an argument, so you can mask out the water layer when you call it.
Your answer

Follow this Question
Related Questions
SQL Unity Android 0 Answers
Unexpected Symbol 'break' 2 Answers
Script attached to An enemy but dosent work right if there are multiple enemies. 2 Answers
Problem with Score/Highscore script 0 Answers
Player hiding inside Gameobject 1 Answer