Description
The WithAlpha
method allows you to create a new Color
instance with a modified alpha (transparency) value, while keeping the red, green, and blue components unchanged. This method is useful when you need to adjust the transparency of a color without altering its hue or brightness.
Usage
To use the WithAlpha
method, call it on an existing Color
instance and pass the desired alpha value as a float
parameter. The alpha value should be between 0 (fully transparent) and 1 (fully opaque).
Example
// Example of using the WithAlpha method
Color originalColor = Color.Red; // A fully opaque red color
Color semiTransparentRed = originalColor.WithAlpha(0.5f); // Creates a red color with 50% transparency
// Output the RGBA values
float r = semiTransparentRed.r; // Red component
float g = semiTransparentRed.g; // Green component
float b = semiTransparentRed.b; // Blue component
float a = semiTransparentRed.a; // Alpha component (0.5)