Hi there, I’m trying to compare 2 colour variables but having no success.
Setting them like this:
private var colour1 : Color = new Color(1.000, 0.945, 0.000, 1.000);
// uvPoint refers to a conversion from a RaycastHit2D's point to uv coordinates
private var colour2 : Color = theSprite.texture.GetPixel(uVPoint.x, uVPoint.y);
And comparing like this:
// This happens on clicking on the colour.
if (colour1 == colour2)
{
print("colour1 = colour2");
print("colour1 = "+ colour1);
print("colour2 = "+ colour2);
}
else if (colour1 != colour2)
{
print("colour1 != colour2");
print("colour1 = "+ colour1);
print("colour2 = "+ colour2);
}
I keep getting the results:
colour1 != colour2
colour1 = RGBA(1.000, 0.949, 0.000, 1.000)
colour2 = RGBA(1.000, 0.949, 0.000, 1.000)
So if both colour variables have identical contents am I missing something fundamental about how colors should be compared?
The sprite texture is set to RGBA 32 bit, if that helps anything…
Thanks very much!
UPDATE:
Tried to print each individual colour value, which gives fuller results. Here’s the culprit:
colour1.g = 0.9490196
colour2.g = 0.949
Am now wondering if using Color32 would solve this issue or if it would have the same issue? (Looking into it and will post an answer soon)