Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Color

Representation of RGBA colors.
Read time 2 minutesLast updated 4 days ago

Definition

public struct Color : IEquatable<Color>, IFormattable

Remarks

This structure is used throughout Unity to pass colors around. Each color component is a floating point value with a range from 0 to 1.
Components (Color.r,Color.g,Color.b) define a color in RGB color space. Alpha component (Color.a) defines transparency - alpha of one is completely opaque, alpha of zero is completely transparent.

Fields

Value

Description

aAlpha component of the color (0 is transparent, 1 is opaque).
bBlue component of the color.
gGreen component of the color.
rRed component of the color.

Constructors

Constructor

Description

Color(System.Single,System.Single,System.Single)Constructs a new Color with given r,g,b components and sets a to 1.
Color(System.Single,System.Single,System.Single,System.Single)Constructs a new Color with given r,g,b,a components.

Properties

Property

Description

gammaA version of the color that has had the gamma curve applied.
grayscaleThe grayscale value of the color. (Read Only)
this[]Access the r, g, b,a components using [0], [1], [2], [3] respectively.
linearA linear value of an sRGB color.
maxColorComponentReturns the maximum color component value: Max(r,g,b).

Static Properties

Property

Description

blackSolid black. RGBA is (0, 0, 0, 1).
blueSolid blue. RGBA is (0, 0, 1, 1).
clearCompletely transparent. RGBA is (0, 0, 0, 0).
cyanCyan. RGBA is (0, 1, 1, 1).
grayGray. RGBA is (0.5, 0.5, 0.5, 1).
greenSolid green. RGBA is (0, 1, 0, 1).
greyEnglish spelling for Color.gray. RGBA is the same (0.5, 0.5, 0.5, 1).
magentaMagenta. RGBA is (1, 0, 1, 1).
redSolid red. RGBA is (1, 0, 0, 1).
whiteSolid white. RGBA is (1, 1, 1, 1).
yellowYellow. RGBA is (1, 0.92, 0.016, 1), but the color is nice to look at!

Methods

Method

Description

ToStringReturns a formatted string of this color.

Static Methods

Method

Description

HSVToRGBCreates an RGB colour from HSV input.
LerpLinearly interpolates between colors a and b by t.
LerpUnclampedLinearly interpolates between colors a and b by t.
RGBToHSVCalculates the hue, saturation and value of an RGB input color.

Operators

Operator

Description

operator +Adds two colors together. Each component is added separately.
operator /Divides color a by the float b. Each color component is scaled separately.
Vector4Colors can be implicitly converted to and from Vector4.
ColorColors can be implicitly converted to and from Vector4.
operator *Multiplies color a by the float b. Each color component is scaled separately.
operator -Subtracts color b from color a. Each component is subtracted separately.