layerMask in Linecast doesn't work?

Here is my Layer setting:alt text

Here is my code:if(Physics.Linecast( startPoint,endPoint,out rh,9)){ Debug.DrawLine(startPoint,endPoint); Debug.Log(rh.point); }

and neither I set my object in layer “User Layer 8” or “User Layer 9”,and when the object
across the line between two position, nothing happen.
What’s the matter?
Thx…

Its because you should pass a bitmask as a parameter. See this explanation. You actually want this:

var layerMask = (1 << 8) | (1<<9);

if(Physics.Linecast( startPoint,endPoint,out rh,layerMask)) {
    Debug.DrawLine(startPoint,endPoint); Debug.Log(rh.point); 
}

The link explains what that all means. You want to shift the bit representation 8 and 9 bits to the left. Then, The linecast checks where the 1’s and 0’s are in the bit mask. It will check collisions against layers that correspond to a 1 and ignore layers with a 0.