How do I Convert Color RGB values to Int to compare two different colors at runtime?

So I’m setting a cube to a random color.Lerp value between Red & Green. Which in Debug displays as 4 float values for each RGBA. Example: (0.428, 0.572, 0.000, 1.000)

Then I want to check if these values are smaller or greater than a pre-defined RGBA value which if so would trigger an event. For example: Check to see if the first color is more red than green in shade if so, trigger an event. (I can handle the triggering, that’s easy).

Now I know I have to do some conversion because Color comparisons are not allowed, only equal == or not equal != comparisons. I want to be able to compare >= or <= between the RGBA values. Which from my research would require converting it to an int, uint or float.

So this is where I’m stuck. How do I accomplish color RGBA value conversions so that I can easily compare them as ints or floats. Any help would be greatly appreciated. Or any other suggestion I’m not thinking about is welcomed. Long time reader first time poster.

Unity has two different color formats. The Color class uses four floats between 0.0 and 1.0. The Color32 class uses typical RGBA going from 0 to 255 for each component. And they can be implicitly converted. So you can do:

Color c = new Color(0.428f, 0.572f, 0.000f, 1.000f);
Color32 cc = c;

Now you can refer to cc.r, cc.g, cc.b, and cc.a, and the values will be integers. Actually they are bytes, but they are integer values.

Now I know I have to do some
conversion because Color comparisons
are not allowed, only equal == or not
equal != comparisons. I want to be
able to compare >= or <= between the
RGBA values. Which from my research
would require converting it to an int,
uint or float.

Either ints or floats, you cannot compare colors. But you can compare individual components of colors. So if you had these:

Color c1 = new Color(0.428f, 0.572f, 0.000f, 1.000f);
Color c2 = new Color(0.315f, 0.427f, 0.643f, 1.000f);

…you can do:

if (c1.b > c2.b) {
     // Do something
}

And that would work for both Color and Color32.