Color

A color value stored as 4 floats with values that are generally between 0 and 1! Note that there’s also a Color32 structure, and that 4 floats is generally a lot more than you need. So, use this for calculating individual colors at quality, but maybe store them en-masse with Color32!

Also note that RGB is often a terrible color format for picking colors, but it’s how our displays work and we’re stuck with it. If you want to create a color via code, try out the static Color.HSV method instead!

Instance Fields and Properties

   
float a Alpha, or opacity component, a value that is generally between 0-1, where 0 is completely transparent, and 1 is completely opaque.
float b Blue component, a value that is generally between 0-1
float g Green component, a value that is generally between 0-1
float r Red component, a value that is generally between 0-1

Instance Methods

   
Color Try Color.HSV instead! But if you really need to create a color from RGB values, I suppose you’re in the right place. All parameter values are generally in the range of 0-1.
ToHSV Converts the color to a Hue/Saturation/Value format! Does not consider transparency when calculating the result.
ToLAB Converts the RGB color to a CIE LAB color space value! Conversion back and forth from LAB space could be somewhat lossy.

Static Fields and Properties

   
Color Black Pure opaque black! Same as (0,0,0,1).
Color BlackTransparent Pure transparent black! Same as (0,0,0,0).
Color White Pure opaque white! Same as (1,1,1,1).

Static Methods

   
HSV Creates a Red/Green/Blue color from Hue/Saturation/Value information.
LAB Creates an RGB color from a CIE-Lab color space. CIE-Lab is a color space that models human perception, and has significantly more accurate to perception lightness values, so this is an excellent color space for color operations that wish to preserve color brightness properly. Traditionally, values are L [0,100], a,b [-200,+200] but here we normalize them all to the 0-1 range. If you hate it, let me know why!

Examples

// You can create a color using Red, Green, Blue, Alpha values,
// but it's often a great recipe for making a bad color.
Color color = new Color(1,0,0,1); // Red

// Hue, Saturation, Value, Alpha is a more natural way of picking
// colors. The commentdocs have a list of important values for Hue,
// to make it a little easier to pick the hue you want.
color = Color.HSV(0, 1, 1, 1); // Red

// And there's a few static colors available if you need 'em.
color = Color.White;

// You can also implicitly convert Color to a Color32!
Color32 color32 = color;