- Home /
Game says colors are different but they actually aren't?
I have a player and if the player collides with an obstacle that's the same color as them if(obstacle.color == player.color) the player's color randomizes. However, When the player collides with the red obstacle (and they're red) it says it's a different color. But if I use the pipette tool to change the obstacle color and grab the color from the player right before they collide, then it says they're the same. And here's the strangest thing: if I use the pipette tool on the obstacle itself (the color doesnt change at ALL) right before the player hits, then it works. What?!
Any advice on how to troubleshoot this? I'm super confused as of right now.
What object type is the obstacle? What is the color property? it is entirely possible that the color you pick from the screen is different from whatever the property is, because of how it's rendered. The color is just a property of the shader, in the end. It may be affected by the material shader/ texture, lighting, post processing, etc. also, provided the color property is of type Color, it is composed of four floating point numbers. They must be exactly the same (not approximately the same) in order for this to work
Answer by SteenPetersen · May 14, 2019 at 09:38 PM
This could be due to floating point precision issues you may wish to do something like this
if (Mathf.Approximately(color1.r, color2.r))
{
// do stuff
}
Your answer