how do i detect a color (material) on the player when it hits a object

so basically i’m trying to make a game where the player can change color to blue,white,red and green and if its the same color as the obstacle you wont get a game over but if you have a different color than the obstacle then its a game over but i don’t know how to make it so that if you have the same color you won’t get a game over. can i have some help?

An obstacle can’t have only one color, so color is just an appearance, not something you can rely on. Your underlying rule is, game objects are divide into groups. If a player collides with obstacles from different groups, it dies.

  1. Add field public int groupNum in player’s and obstacle’s script and set them.

  2. Change player’s and obstacle’s color in their Start() according to their groupNum.

  3. In player’s script, use OnCollisionEnter to check collisions. If the colliding target is an obstacle and it’s in the different group then that player dies.

Hi @bacon_canadian is your game 2d or 3d?

@potter613770 its 3D