So, I have this code:
if(Input.GetMouseButtonDown(0)){
ray = Camera.main.ScreenToWorldPoint(Input.mousePosition);
hit = Physics2D.Raycast(ray, Vector2.zero, maskLayer2.value);
if(hit.collider != null){
TagName = hit.transform.tag;
}
}
And I have two different objects with their respective layers: layer1 and layer2, and I want the raycast to detect the object in layer2. The thing is, their colliders overlap and the raycast only detects the collider of layer1 ending up giving the wrong TagName. The only layer in LayerMask is layer2, so I don’t know what to do. Does anyone know how to solve this?
Enchanta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.