Collider.Raycast Issue

Hi,

I’m trying to use raycasting to get the location of the mouse on the surface of a cube. However I can’t figure out how to get the raycast to ignore all other colliders. I looked at the unity script reference for Collider.Raycast at Unity - Scripting API: Collider.Raycast but I still don’t understand where you declare which collider the ray should be looking for. Any help would be greatly appreciated.

Thank you,

-dbrom

Not sure, but can’t you try tagging it and checking if your ray hits a object with the specified tag? Or try checking the object simply by its name…

Something like…

if(hit.transform == cube){
//whatever you want to do with it.. 
}

The way to do it is to put the cube in a layer by itself and then use Raycast() with a layermask parameter with only that layer enabled in the mask.

You could put the cube into that layer just before the test and then add it back after so you don’t have to maintain identical collision masks in the physics settings.

Excellent! That worked perfectly. Thank you very much!