Hello everyone, I made a simple if statement comparing the RGB of a color, but it is returning false even when the values correspond. How do I compara colors without this happening?
if(sprite.color.r == 30 && sprite.color.g == 250 && sprite.color.b == 150)
{
sprite.color = rustic1; //rustic1 is a color
}
color values are between 0f and 1f, where value 0f means 0 and value 1f means 255, so if you want to compare with range 0…255, you need to divide your values by 255f.
Color color2 = new Color(30/255f, 250/255f, 150/255f, sprite.color.a);
if(sprite.color == color2)
{
sprite.color = rustic1; //rustic1 is a color
}