How do you make a player pass through a wall depending on the color

Hello everyone, I’m making a game in unity 3D and I have it so I am a cube who can roll around and do the normal, but I want to add a bit of puzzle into my game. I have made it so the player can change color between red, blue and green then have black as default, but I could not figure out how to make it so if the player is blue, he can pass through blue walls, red, red walls etc. Can anyone help me with this? I am writing in c#.

You can use Layer-based collision detection, and apply layers to your walls. Blue walls will have the “Blue” layer, red ones the “Red” layer, etc. Open your collision matrix (Edit > Project Settings > Physics) and set it so that Blue GameObjects don’t collide with other Blue GameObjects, etc.

Then when you change your cube’s color, you can also change its layer, so that it won’t collide with walls that are on the same layer.