I have read articles and other peoples posts about layer masks, and I can't get this to work. I am testing to see if a point in my game is within an objects mesh. So I found this code that easily does this:
http://answers.unity3d.com/questions/163864/test-if-point-is-in-collider.html
Now am adding a layer mask to the one and only object I want to test if my coordinate is inside of (Nothing else in my game should affect the ray cast). I created a layer (layer 9 in this case) that my gameobject "sphere" is assigned to, and then used the code in the link above to test if my coordinate is within my "sphere". But for some reason, the raycast is still affected by other objects in the game. Here is my code that I use to create the layer mask for anyone willing to help:
internal var hitObjectMask : LayerMask = ~(1 << 9);//this is the layer mask
internal var hitObject : GameObject; //This is the sphere that I talked about above.
hitObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
hitObject.AddComponent(MeshCollider);
hitObject.layer = LayerMask.NameToLayer("SpawnOutline");//this is the name of layer 9
And just in case your wondering, here is how im using the raycast:
if( Physics.Linecast(Point, Start, hit,hitObjectMask)) {
↧