Layer-based collision detection is a way to make a GameObject collide with another GameObject that’s set up on a specific layer or layers.
The Layer Collision Matrix defines which GameObjects can collide with which Layers. To open the Layer Collision Matrix go to Edit > Project Settings > Physics.
In the image, the Layer Collision Matrix is set up so that only GameObjects that belong to the same layer can collide:
If, for example, you want Layer 1 to collide with Layer 2 and 3, but not with Layer 1, find the row for Layer 1, then check the boxes for the Layer 2 and Layer 3 columns, and leave the Layer 1 column checkbox blank.
Select the GameObject you want to assign a layer to.
In the Inspector, select the Layer dropdown at the top, and either choose a Layer or add a new Layer. Repeat for each GameObject until you have finished assigning your GameObjects to Layers.
In the Unity menu bar, go to Edit > Project Settings, then select the Physics category to open the Physics window.
Select the layers on the Collision Matrix that you want to interact with the other layers.