Here is my code: Code (CSharp): Physics.Raycast (ray,out hit,90,mask); //Debug.DrawLine (TimingLight.position,direction,Color.blue,9); if (hit.transform != null) { //Debug.Log (hit.transform.name); var LayerHit = hit.transform.gameObject.layer; if (LayerHit != 12) { return LayerHit// <-----Here this is 10? } the mask is set with check marks by 2 layers (layer 11 and 12) So how is it EVER 10? I tried reversing the mask so everything BUT 11 and 12 are checked but then i get layers like 18, etc... what is going on here?
i just tried this as well: based on examples here (http://unity3d-book.blogspot.com/2014/03/unity3d-raycast-with-layermask-how-do.html): Code (CSharp): var Cones = 1 << 12;// cones is layer 12 var Timing = 1 << 11;//Timing is layer 11 ; var Mask2 = Cones | Timing; Vector3 direction = TimingLight.TransformDirection(new Vector3(0,-200,0)); var ray = new Ray(TimingLight.position, direction); RaycastHit hit; Physics.Raycast (ray,out hit,90,Mask2); //Debug.DrawLine (TimingLight.position,direction,Color.blue,9); if (hit.transform != null) { //Debug.Log (hit.transform.name); var LayerHit = hit.transform.gameObject.layer; //Debug.DrawLine(TimingLight.position,hit.point,Color.yellow); //if ((ConeMask.value & 1 << LayerHit) == 0) if (LayerHit != 12) //11=timing { return BeamTrippedState.Front; } } Still hitting layer 10...
I finally figured it out... It was caused buy the fact that my colider was a child of a Rigid body... So change the code to Code (CSharp): hit.collider.gameObject instead of hit.transform