Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Color

Representation of RGBA colors.
Read time 12 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.

Examples

using UnityEngine;public class ColorExample : MonoBehaviour{ void Start() { // Initialize with RGB Color redColor = new Color(1f, 0f, 0f); // Initialize with RGBA Color blueWithAlpha = new Color(0f, 0f, 1f, 0.5f); // Initialize with hex ColorUtility.TryParseHtmlString("#00FF00", out Color greenFromHex); // Initialize with HSV float hue = 0.6f; float saturation = 0.9f; float value = 0.7f; Color fromHSV = Color.HSVToRGB(hue, saturation, value); // Use some of the preset colors Color cornflower = Color.cornflowerBlue; Color lawn = Color.lawnGreen; Color lemon = Color.lemonChiffon; Color violet = Color.violet; // Create complementary color Color complementary = new Color( 1f - redColor.r, 1f - redColor.g, 1f - redColor.b ); // Lerp between colors Color lerpedColor = Color.Lerp(redColor, blueWithAlpha, 0.5f); // Darken color Color darkercolor = lerpedColor * 0.8f; // Lighten color Color lighterColor = lerpedColor + Color.white * 0.2f; }}

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 color value in linear space converted from an sRGB value.
maxColorComponentReturns the maximum color component value: Max(r,g,b).

Static Properties

Property

Description

aliceBlueColor Preset of
RGBA(0.9411765f, 0.9725491f, 1f, 1f)
antiqueWhiteColor Preset of
RGBA(0.9803922f, 0.9215687f, 0.8431373f, 1f)
aquamarineColor Preset of
RGBA(0.4980392f, 1f, 0.8313726f, 1f)
azureColor Preset of
RGBA(0.9411765f, 1f, 1f, 1f)
beigeColor Preset of
RGBA(0.9607844f, 0.9607844f, 0.8627452f, 1f)
bisqueColor Preset of
RGBA(1f, 0.8941177f, 0.7686275f, 1f)
blackColor Preset of
RGBA(0f, 0f, 0f, 1f)
blanchedAlmondColor Preset of
RGBA(1f, 0.9215687f, 0.8039216f, 1f)
blueColor Preset of
RGBA(0f, 0f, 1f, 1f)
blueVioletColor Preset of
RGBA(0.5411765f, 0.1686275f, 0.8862746f, 1f)
brownColor Preset of
RGBA(0.6470588f, 0.1647059f, 0.1647059f, 1f)
burlywoodColor Preset of
RGBA(0.8705883f, 0.7215686f, 0.5294118f, 1f)
cadetBlueColor Preset of
RGBA(0.372549f, 0.6196079f, 0.627451f, 1f)
chartreuseColor Preset of
RGBA(0.4980392f, 1f, 0f, 1f)
chocolateColor Preset of
RGBA(0.8235295f, 0.4117647f, 0.1176471f, 1f)
clearColor Preset of
RGBA(0f, 0f, 0f, 0f)
coralColor Preset of
RGBA(1f, 0.4980392f, 0.3137255f, 1f)
cornflowerBlueColor Preset of
RGBA(0.3921569f, 0.5843138f, 0.9294118f, 1f)
cornsilkColor Preset of
RGBA(1f, 0.9725491f, 0.8627452f, 1f)
crimsonColor Preset of
RGBA(0.8627452f, 0.07843138f, 0.2352941f, 1f)
cyanColor Preset of
RGBA(0f, 1f, 1f, 1f)
darkBlueColor Preset of
RGBA(0f, 0f, 0.5450981f, 1f)
darkCyanColor Preset of
RGBA(0f, 0.5450981f, 0.5450981f, 1f)
darkGoldenRodColor Preset of
RGBA(0.7215686f, 0.5254902f, 0.04313726f, 1f)
darkGrayColor Preset of
RGBA(0.6627451f, 0.6627451f, 0.6627451f, 1f)
darkGreenColor Preset of
RGBA(0f, 0.3921569f, 0f, 1f)
darkKhakiColor Preset of
RGBA(0.7411765f, 0.7176471f, 0.4196079f, 1f)
darkMagentaColor Preset of
RGBA(0.5450981f, 0f, 0.5450981f, 1f)
darkOliveGreenColor Preset of
RGBA(0.3333333f, 0.4196079f, 0.1843137f, 1f)
darkOrangeColor Preset of
RGBA(1f, 0.5490196f, 0f, 1f)
darkOrchidColor Preset of
RGBA(0.6f, 0.1960784f, 0.8000001f, 1f)
darkRedColor Preset of
RGBA(0.5450981f, 0f, 0f, 1f)
darkSalmonColor Preset of
RGBA(0.9137256f, 0.5882353f, 0.4784314f, 1f)
darkSeaGreenColor Preset of
RGBA(0.5607843f, 0.7372549f, 0.5607843f, 1f)
darkSlateBlueColor Preset of
RGBA(0.282353f, 0.2392157f, 0.5450981f, 1f)
darkSlateGrayColor Preset of
RGBA(0.1843137f, 0.3098039f, 0.3098039f, 1f)
darkTurquoiseColor Preset of
RGBA(0f, 0.8078432f, 0.8196079f, 1f)
darkVioletColor Preset of
RGBA(0.5803922f, 0f, 0.8274511f, 1f)
deepPinkColor Preset of
RGBA(1f, 0.07843138f, 0.5764706f, 1f)
deepSkyBlueColor Preset of
RGBA(0f, 0.7490196f, 1f, 1f)
dimGrayColor Preset of
RGBA(0.4117647f, 0.4117647f, 0.4117647f, 1f)
dodgerBlueColor Preset of
RGBA(0.1176471f, 0.5647059f, 1f, 1f)
firebrickColor Preset of
RGBA(0.6980392f, 0.1333333f, 0.1333333f, 1f)
floralWhiteColor Preset of
RGBA(1f, 0.9803922f, 0.9411765f, 1f)
forestGreenColor Preset of
RGBA(0.1333333f, 0.5450981f, 0.1333333f, 1f)
gainsboroColor Preset of
RGBA(0.8627452f, 0.8627452f, 0.8627452f, 1f)
ghostWhiteColor Preset of
RGBA(0.9725491f, 0.9725491f, 1f, 1f)
goldColor Preset of
RGBA(1f, 0.8431373f, 0f, 1f)
goldenRodColor Preset of
RGBA(0.854902f, 0.6470588f, 0.1254902f, 1f)
grayColor Preset of
RGBA(0.5f, 0.5f, 0.5f, 1f)
gray1Color Preset of
RGBA(0.1f, 0.1f, 0.1f, 1f)
gray2Color Preset of
RGBA(0.2f, 0.2f, 0.2f, 1f)
gray3Color Preset of
RGBA(0.3f, 0.3f, 0.3f, 1f)
gray4Color Preset of
RGBA(0.4f, 0.4f, 0.4f, 1f)
gray5Color Preset of
RGBA(0.5f, 0.5f, 0.5f, 1f)
gray6Color Preset of
RGBA(0.6f, 0.6f, 0.6f, 1f)
gray7Color Preset of
RGBA(0.7f, 0.7f, 0.7f, 1f)
gray8Color Preset of
RGBA(0.8f, 0.8f, 0.8f, 1f)
gray9Color Preset of
RGBA(0.9f, 0.9f, 0.9f, 1f)
greenColor Preset of
RGBA(0f, 1f, 0f, 1f)
greenYellowColor Preset of
RGBA(0.6784314f, 1f, 0.1843137f, 1f)
greyColor Preset of
RGBA(0.5f, 0.5f, 0.5f, 1f)
honeydewColor Preset of
RGBA(0.9411765f, 1f, 0.9411765f, 1f)
hotPinkColor Preset of
RGBA(1f, 0.4117647f, 0.7058824f, 1f)
indianRedColor Preset of
RGBA(0.8039216f, 0.3607843f, 0.3607843f, 1f)
indigoColor Preset of
RGBA(0.2941177f, 0f, 0.509804f, 1f)
ivoryColor Preset of
RGBA(1f, 1f, 0.9411765f, 1f)
khakiColor Preset of
RGBA(0.9411765f, 0.9019608f, 0.5490196f, 1f)
lavenderColor Preset of
RGBA(0.9019608f, 0.9019608f, 0.9803922f, 1f)
lavenderBlushColor Preset of
RGBA(1f, 0.9411765f, 0.9607844f, 1f)
lawnGreenColor Preset of
RGBA(0.4862745f, 0.9882354f, 0f, 1f)
lemonChiffonColor Preset of
RGBA(1f, 0.9803922f, 0.8039216f, 1f)
lightBlueColor Preset of
RGBA(0.6784314f, 0.8470589f, 0.9019608f, 1f)
lightCoralColor Preset of
RGBA(0.9411765f, 0.5019608f, 0.5019608f, 1f)
lightCyanColor Preset of
RGBA(0.8784314f, 1f, 1f, 1f)
lightGoldenRodColor Preset of
RGBA(0.9333334f, 0.8666667f, 0.509804f, 1f)
lightGoldenRodYellowColor Preset of
RGBA(0.9803922f, 0.9803922f, 0.8235295f, 1f)
lightGrayColor Preset of
RGBA(0.8274511f, 0.8274511f, 0.8274511f, 1f)
lightGreenColor Preset of
RGBA(0.5647059f, 0.9333334f, 0.5647059f, 1f)
lightPinkColor Preset of
RGBA(1f, 0.7137255f, 0.7568628f, 1f)
lightSalmonColor Preset of
RGBA(1f, 0.627451f, 0.4784314f, 1f)
lightSeaGreenColor Preset of
RGBA(0.1254902f, 0.6980392f, 0.6666667f, 1f)
lightSkyBlueColor Preset of
RGBA(0.5294118f, 0.8078432f, 0.9803922f, 1f)
lightSlateBlueColor Preset of
RGBA(0.5176471f, 0.4392157f, 1f, 1f)
lightSlateGrayColor Preset of
RGBA(0.4666667f, 0.5333334f, 0.6f, 1f)
lightSteelBlueColor Preset of
RGBA(0.6901961f, 0.7686275f, 0.8705883f, 1f)
lightYellowColor Preset of
RGBA(1f, 1f, 0.8784314f, 1f)
limeGreenColor Preset of
RGBA(0.1960784f, 0.8039216f, 0.1960784f, 1f)
linenColor Preset of
RGBA(0.9803922f, 0.9411765f, 0.9019608f, 1f)
magentaColor Preset of
RGBA(1f, 0f, 1f, 1f)
maroonColor Preset of
RGBA(0.6901961f, 0.1882353f, 0.3764706f, 1f)
mediumAquamarineColor Preset of
RGBA(0.4f, 0.8039216f, 0.6666667f, 1f)
mediumBlueColor Preset of
RGBA(0f, 0f, 0.8039216f, 1f)
mediumOrchidColor Preset of
RGBA(0.7294118f, 0.3333333f, 0.8274511f, 1f)
mediumPurpleColor Preset of
RGBA(0.5764706f, 0.4392157f, 0.8588236f, 1f)
mediumSeaGreenColor Preset of
RGBA(0.2352941f, 0.7019608f, 0.4431373f, 1f)
mediumSlateBlueColor Preset of
RGBA(0.482353f, 0.4078432f, 0.9333334f, 1f)
mediumSpringGreenColor Preset of
RGBA(0f, 0.9803922f, 0.6039216f, 1f)
mediumTurquoiseColor Preset of
RGBA(0.282353f, 0.8196079f, 0.8000001f, 1f)
mediumVioletRedColor Preset of
RGBA(0.7803922f, 0.08235294f, 0.5215687f, 1f)
midnightBlueColor Preset of
RGBA(0.09803922f, 0.09803922f, 0.4392157f, 1f)
mintCreamColor Preset of
RGBA(0.9607844f, 1f, 0.9803922f, 1f)
mistyRoseColor Preset of
RGBA(1f, 0.8941177f, 0.882353f, 1f)
moccasinColor Preset of
RGBA(1f, 0.8941177f, 0.7098039f, 1f)
navajoWhiteColor Preset of
RGBA(1f, 0.8705883f, 0.6784314f, 1f)
navyBlueColor Preset of
RGBA(0f, 0f, 0.5019608f, 1f)
oldLaceColor Preset of
RGBA(0.9921569f, 0.9607844f, 0.9019608f, 1f)
oliveColor Preset of
RGBA(0.5019608f, 0.5019608f, 0f, 1f)
oliveDrabColor Preset of
RGBA(0.4196079f, 0.5568628f, 0.1372549f, 1f)
orangeColor Preset of
RGBA(1f, 0.6470588f, 0f, 1f)
orangeRedColor Preset of
RGBA(1f, 0.2705882f, 0f, 1f)
orchidColor Preset of
RGBA(0.854902f, 0.4392157f, 0.8392158f, 1f)
paleGoldenRodColor Preset of
RGBA(0.9333334f, 0.909804f, 0.6666667f, 1f)
paleGreenColor Preset of
RGBA(0.5960785f, 0.9843138f, 0.5960785f, 1f)
paleTurquoiseColor Preset of
RGBA(0.6862745f, 0.9333334f, 0.9333334f, 1f)
paleVioletRedColor Preset of
RGBA(0.8588236f, 0.4392157f, 0.5764706f, 1f)
papayaWhipColor Preset of
RGBA(1f, 0.937255f, 0.8352942f, 1f)
peachPuffColor Preset of
RGBA(1f, 0.854902f, 0.7254902f, 1f)
peruColor Preset of
RGBA(0.8039216f, 0.5215687f, 0.2470588f, 1f)
pinkColor Preset of
RGBA(1f, 0.7529413f, 0.7960785f, 1f)
plumColor Preset of
RGBA(0.8666667f, 0.627451f, 0.8666667f, 1f)
powderBlueColor Preset of
RGBA(0.6901961f, 0.8784314f, 0.9019608f, 1f)
purpleColor Preset of
RGBA(0.627451f, 0.1254902f, 0.9411765f, 1f)
rebeccaPurpleColor Preset of
RGBA(0.4f, 0.2f, 0.6f, 1f)
redColor Preset of
RGBA(1f, 0f, 0f, 1f)
rosyBrownColor Preset of
RGBA(0.7372549f, 0.5607843f, 0.5607843f, 1f)
royalBlueColor Preset of
RGBA(0.254902f, 0.4117647f, 0.882353f, 1f)
saddleBrownColor Preset of
RGBA(0.5450981f, 0.2705882f, 0.07450981f, 1f)
salmonColor Preset of
RGBA(0.9803922f, 0.5019608f, 0.4470589f, 1f)
sandyBrownColor Preset of
RGBA(0.9568628f, 0.6431373f, 0.3764706f, 1f)
seaGreenColor Preset of
RGBA(0.1803922f, 0.5450981f, 0.3411765f, 1f)
seashellColor Preset of
RGBA(1f, 0.9607844f, 0.9333334f, 1f)
siennaColor Preset of
RGBA(0.627451f, 0.3215686f, 0.1764706f, 1f)
silverColor Preset of
RGBA(0.7529413f, 0.7529413f, 0.7529413f, 1f)
skyBlueColor Preset of
RGBA(0.5294118f, 0.8078432f, 0.9215687f, 1f)
slateBlueColor Preset of
RGBA(0.4156863f, 0.3529412f, 0.8039216f, 1f)
slateGrayColor Preset of
RGBA(0.4392157f, 0.5019608f, 0.5647059f, 1f)
snowColor Preset of
RGBA(1f, 0.9803922f, 0.9803922f, 1f)
softBlueColor Preset of
RGBA(0.1882353f, 0.682353f, 0.7490196f, 1f)
softGreenColor Preset of
RGBA(0.5490196f, 0.7882354f, 0.1411765f, 1f)
softRedColor Preset of
RGBA(0.8627452f, 0.1921569f, 0.1960784f, 1f)
softYellowColor Preset of
RGBA(1f, 0.9333334f, 0.5490196f, 1f)
springGreenColor Preset of
RGBA(0f, 1f, 0.4980392f, 1f)
steelBlueColor Preset of
RGBA(0.2745098f, 0.509804f, 0.7058824f, 1f)
tanColor Preset of
RGBA(0.8235295f, 0.7058824f, 0.5490196f, 1f)
tealColor Preset of
RGBA(0f, 0.5019608f, 0.5019608f, 1f)
thistleColor Preset of
RGBA(0.8470589f, 0.7490196f, 0.8470589f, 1f)
tomatoColor Preset of
RGBA(1f, 0.3882353f, 0.2784314f, 1f)
turquoiseColor Preset of
RGBA(0.2509804f, 0.8784314f, 0.8156863f, 1f)
violetColor Preset of
RGBA(0.9333334f, 0.509804f, 0.9333334f, 1f)
violetRedColor Preset of
RGBA(0.8156863f, 0.1254902f, 0.5647059f, 1f)
wheatColor Preset of
RGBA(0.9607844f, 0.8705883f, 0.7019608f, 1f)
whiteColor Preset of
RGBA(1f, 1f, 1f, 1f)
whiteSmokeColor Preset of
RGBA(0.9607844f, 0.9607844f, 0.9607844f, 1f)
yellowColor Preset of
RGBA(1f, 0.92f, 0.016f, 1f)
.
yellowGreenColor Preset of
RGBA(0.6039216f, 0.8039216f, 0.1960784f, 1f)
yellowNiceColor Preset of
RGBA(1f, 0.92f, 0.016f, 1f)

Methods

Method

Description

EqualsReturns true if the given color is exactly equal to this color, i.e. if the red, green, blue, and alpha values are exactly the same.
GetHashCodeReturns the hash code for this color. This lets you use colors as keys in hash tables.
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
using the interpolation ratio
t
.
LerpUnclampedLinearly interpolates between colors
a
and
b
using the interpolation ratio
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.
operator ==Returns true if two Colors are approximately equal.
Vector4Colors can be implicitly converted to and from Vector4.
ColorColors can be implicitly converted to and from Vector4.
operator !=Returns true if colors are not equal.
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.