raycast detect a child collider that is not supose to?

Hello again, i got a small problem … i am using a raycast to detect the collider of a certain layer(LayerA)

The problem is that the gameobject that contain the collider in the LayerA as a child mark as LayerB that contain a bigger collider and is triggered.

it seams that the raycast detect the collider of the object in the LayerB and the one in the LayerA.
i want the raycast to detect only the LayerA

Here’s the part of the code:

if(Physics.Raycast(PlayerCamera.transform.TransformPoint(0,0,0.5f), PlayerCamera.transform.forward, out Detection,DetectionDistance))
		{
                if (Detection.transform.gameObject.layer == LayerMask.NameToLayer("LayerA") )
		     {
                      DetectedItem = Detection.transform.gameObject;
                     if(Input.GetButtonDown("Action")) 
                          {
                           //Do Something
                          }
                 }
       }

it seems that i can press the “Action” button even if the raycast detect the LayerB

Ah, I understand what youre trying to achieve now. “Raycast” doesn’t hit multiple objects (“RaycastAll” returns all the objects). The regular Raycast is a bool that returns “true” only once whenever it hits any object specified by the layerMask, or if there is no layerMask, it returns true only once when it hits any object with a collider. So to allow it to hit multiple objects on different layers and decide what to do depending on the layer, you could either return all the objects with RaycastAll and cycle through them, or probably more efficiently, you could do multiple Raycasts (according to your comment) and put them in “if/else” statements so that only one Raycast will return “true” and you could prioritize them according to importance, placing the more important Raycasts higher in the “if/else” statement, so only one Raycast will actually return true.