codeAPI Reference

Sandbox.Color

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Sandbox.Color

RGBA color representation.

Overview

Color stores red, green, blue, and alpha values (0-1 range).

Creation

CSHARP
// From floats (0-1)
Color c = new Color(1, 0, 0, 1); // Red
Color c = new Color(0.5f, 0.5f, 0.5f); // Gray (alpha defaults to 1)

// From bytes (0-255)
Color c = new Color(255, 0, 0, 255);

// From hex
Color c = Color.Parse("#FF0000");

Named Colors

CSHARP
Color red = Color.Red;
Color blue = Color.Blue;
Color green = Color.Green;
Color white = Color.White;
Color black = Color.Black;
Color yellow = Color.Yellow;
Color orange = Color.Orange;
Color cyan = Color.Cyan;
Color magenta = Color.Magenta;
Color gray = Color.Gray;
Color transparent = Color.Transparent;

Components

CSHARP
Color c = renderer.Tint;

float r = c.r; // Red (0-1)
float g = c.g; // Green (0-1)
float b = c.b; // Blue (0-1)
float a = c.a; // Alpha (0-1)

Operations

CSHARP
Color a = Color.Red;
Color b = Color.Blue;

// Addition
Color purple = a + b;

// Scaling
Color lighter = a * 1.5f;

// Lerp
Color orange = Color.Lerp(Color.Red, Color.Yellow, 0.5f);

To/From HSV

CSHARP
// RGB to HSV
float h, s, v;
c.ToHSV(out h, out s, out v);

// HSV to RGB
Color c = Color.FromHSV(h, s, v);

Hex

CSHARP
// To hex string
string hex = c.Hex;

// From hex
Color c = Color.Parse("#RRGGBB");
Color c = Color.Parse("#RRGGBBAA");

Grayscale

CSHARP
Color gray = c.Grayscale;

Usage

CSHARP
// Tint model
renderer.Tint = Color.Red;

// Light color
light.Color = Color.White;

// UI color
panel.Style.BackgroundColor = new Color(0.1f, 0.1f, 0.1f, 0.9f);
Was this helpful?