Search Unity

LayerMask detecting layer it does not contain?

Discussion in 'Editor & General Support' started by renman3000, Jan 22, 2020.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    I have a public LayerMask, in the inspector. I set it to hold two layers. My issue is that, when using Raycast, the ray hits a third layer. I do not want this.

    Code (csharp):
    1.  
    2.  
    3.                 Ray ray = camThis.ScreenPointToRay(Input.mousePosition);
    4.                 RaycastHit hit;
    5.  
    6.                 if(Physics.Raycast(ray, out hit, lm_plate)){
    7.  
    8. }
    9.  
    * lm_plate contains layers x and y, but at hit occurs with layer z. Why? How? Thanks