Hi!
I’m using Unity 5.6.0f3
When I set my object layer to ignore ray cast, Unity put the water mask…
sphereLaserPoint.layer = Physics.IgnoreRaycastLayer;
Then when I go to the editor my sphere is on the Water Mask, Anyone knows what happens?
I try this too:
sphereLaserPoint.layer = 1 << Physics.IgnoreRaycastLayer;
But dont find any layer with this code…
They should definitely both work the same way. If you can post a simple project with the problem happening I can have a look for you.
The correct code to set GameObject.layer so that it ignores raycasts is:
gameObject.layer = 2;
Reference: Unity - Scripting API: GameObject.layer
Physics.IgnoreRaycastLayer is badly named. But if you mouseover it, you’ll see that it doesn’t actually reflect the layer. Instead, it reflects the layer mask of that layer. Remember that layer is not the same as layer mask.
If you want to use that constant, you can, but you’ll need to reverse the mask bitshifting back to the layer index. Something like this:
private static int ReverseBitShift(int mask) {
var retval = 0;
while(mask > 1) {
retval++;
mask /= 2;
}
return retval;
}
But I’d probably just use LayerMask.NameToLayer(“Ignore Raycast”) instead.