Version: Unity 6.1 Alpha (6000.1)
LanguageEnglish
  • C#

Color

struct in UnityEngine

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Representation of RGBA colors.

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 (r,g,b) define a color in RGB color space. Alpha component (a) defines transparency - alpha of one is completely opaque, alpha of zero is completely transparent.

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);

// 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; } }

Static Properties

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 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!

Properties

aAlpha component of the color (0 is transparent, 1 is opaque).
bBlue component of the color.
gGreen component of the color.
gammaA version of the color that has had the gamma curve applied.
grayscaleThe grayscale value of the color. (Read Only)
linearA color value in linear space converted from an sRGB value.
maxColorComponentReturns the maximum color component value: Max(r,g,b).
rRed component of the color.
this[int]Access the r, g, b,a components using [0], [1], [2], [3] respectively.

Constructors

ColorConstructs a new Color with given r,g,b,a components.

Public Methods

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

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

ColorColors can be implicitly converted to and from Vector4.
operator -Subtracts color b from color a. Each component is subtracted separately.
operator !=Returns true if colors are not equal.
operator *Multiplies two colors together. Each component is multiplied separately.
operator /Divides color a by the float b. Each color component is scaled separately.
operator +Adds two colors together. Each component is added separately.
operator ==Returns true if two Colors are approximately equal.
Vector4Colors can be implicitly converted to and from Vector4.