How do I allow an object pass through a wall/object of the same colour/material?

Hi.

Been racking my brain about this but can’t figure it out.

How do I allow the player character to pass through walls/ojects of the same colour/material but trigger a death animation/game over screen if it hits a wall/object of the same colour/material?

Do I put the script on to the wall/objects?

Put objects into different layers. Then setup which layer collides with witch.

Layer based detection would work.

Another alternative would be to use tags and disable the colliders of objects with the right tag.

To add a Layer go to Edit > Project Settings > Tags and Layers. The Inspector will show the tags and layers. You can also add a Layer by going to an Object and in the Inspector Click the Layer dropdown and go to Add a Layer.
To make objects pass thru each other depends on if its 2D or 3D. For 3D go to Edit > Project Settings > Physics and for 2D go to Edit > Project Settings > Physics 2D. The Inspector should show Physics Settings. At the bottom there should be a Matrix (Layer Collision Matrix) with some checkboxes. Uncheck the Layers you do not want to collide. Sorry for some reason I cannot add any pictures or docs.