Color
The Color datatype represents an RGBA (Red Green Blue Alpha) color. Colors are represented with numbers between 0 and 1, where 1 signifies the maximum intensity of a particular color component. RGB components define the color while the Alpha component defines the transparency.
Provides various functions and predefined colors which ranges from common colors like red, green, blue, white, black, to more specific colors such as yellow, cyan, magenta, gray, etc. Further it also provides functionalities such as linear interpolation between two colors, conversion from/to HSV color model, and generating a grayscale color. Unity's Color Documentation
Properties
Access or change the alpha (transparency) component of the color where '1' is fully opaque and '0' is fully transparent. Unity's Color.a Documentation
local color = Color.new(1, 0, 0) -- Red color
color.a = 0.5
print(color.a) -- 0.5
Access or change the blue component value of the color. Unity's Color.b Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.b) -- 0
Predefined black color object with all color components set to zero. As a static property, it can be accessed directly from the class. Unity's Color.black Documentation
Predefined color object with blue component set to maximum and all other components set to zero. One major use of this property can be for quick access to the pure blue color. Unity's Color.blue Documentation
Predefined color object with all components set to zero, resulting in a fully transparent color. Quick access to a transparent color can provide utility in many situations. Unity's Color.clear Documentation
Predefined cyan color object. It provides a quick and convenient way to use cyan in your game. Unity's Color.cyan Documentation
Access or change the green component value of the color. Unity's Color.g Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.g) -- 0
The gamma space equivalent of this color object. When the computations are done in linear space, this conversion can be useful to switch back to Gamma space for rendering. Unity's Color.gamma Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.gamma) -- 0.2126
Predefined gray color object, allowing for quick utilization of gray in a game scene or interface. As a static property, it's accessible directly from the class. Unity's Color.gray Documentation
The grayscale value of the color based on the intensities of the red, green, and blue components. Unity's Color.grayscale Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.grayscale) -- 0.299
Predefined color object with green component at maximum while red, blue, and alpha components at zero. As a static property, it can be accessed directly from the class. Unity's Color.green Documentation
Predefined grey color object. As a static property, it can be accessed directly from the class. This makes it convenient to use grey color quickly and easily. Unity's Color.grey Documentation
The linear (gamma space) equivalent of this color object. Game graphics are usually rendered in a color space known as gamma space, but many computations are done in linear space, thus this property can be useful when such conversions are necessary. Unity's Color.linear Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.linear) -- 0.2126
Predefined magenta color object. It allows quick access to the magenta color. Unity's Color.magenta Documentation
The maximum RGB component in the color. It can be useful when you want to identify the dominant color component. Unity's Color.maxColorComponent Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.maxColorComponent) -- 1
Access or change the red component value of the color. Unity's Color.r Documentation
local color = Color.new(1, 0, 0) -- Red color
print(color.r) -- 1
Predefined Color object with red component set to maximum and all other components set to zero. It's a static property, accessible directly from the class. Unity's Color.red Documentation
Predefined color object with all components set to maximum, producing white color. It is a static property accessible directly from the class. Unity's Color.white Documentation
Predefined yellow color object, offering a quick way to use yellow in your game. It is a static property, accessible directly from the class. Unity's Color.yellow Documentation
Methods
Returns a color with the specified alpha value.
Parameters
a
Returns
Parameters
other
Returns
Convert a color from HSV (Hue, Saturation, Value) color model to RGB (Red, Green, Blue) model. This function can be quite useful whenever you're dealing with HSV colors and need to convert them for use in RGB format. Unity's Color.HSVToRGB Documentation
Parameters
H
The Hue component of the color, ranges between 0 to 1.
S
The Saturation component of the color, ranges between 0 to 1.
V
The Value component of the color, ranges between 0 to 1.
Returns
Returns a Color object in RGB color space.
Convert a color from HSV (Hue, Saturation, Value) color model to RGB (Red, Green, Blue) model. This function can be quite useful whenever you're dealing with HSV colors and need to convert them for use in RGB format. Unity's Color.HSVToRGB Documentation
Parameters
H
The Hue component of the color, ranges between 0 to 1.
S
The Saturation component of the color, ranges between 0 to 1.
V
The Value component of the color, ranges between 0 to 1.
hdr
Returns
Returns a Color object in RGB color space.
Calculates and returns a color that is a certain percentage (defined by the third parameter) between two other colors. This can be used to smoothly transition between two colors. Unity's Color.Lerp Documentation
local colorA = Color.new(1, 0, 0) -- Red color
local colorB = Color.new(0, 1, 0) -- Green color
local transitionColor = Color.Lerp(colorA, colorB, 0.5) -- Transition color between red and green
Works similarly to 'Lerp', but without clamping the percentage (third parameter) between 0 and 1. This allows for extrapolation beyond the two original colors. Unity's Color.LerpUnclamped Documentation
local colorA = Color.new(1, 0, 0) -- Red color
local colorB = Color.new(0, 1, 0) -- Green color
local transitionColor = Color.LerpUnclamped(colorA, colorB, 1.5) -- Extrapolated color beyond red and green
Returns a color with the alpha value multiplied by the specified factor.
Parameters
a
Returns
Parameters
rgbColor
Returns
Returns a hexadecimal string with the format #RRGGBB that can be used in rich text tags.
Returns
Returns the luma value of the color, which represents its brightness.
Returns
Updated 9 days ago