Game Development Reference
In-Depth Information
The fourth value, the alpha property, is the degree of transparency, where 0 is clear and 1 is
solid. The color shortcuts listed in Figure 4-12 include the r, g, b, a values so you can see what
combination makes up the resultant shortcut color.
Figure 4-12. Shortcut colors provided in the Color class
For any color other than the shortcuts, you'll have to set the r, g, b, a values directly. Edit the script
to the following:
#pragma strict
// Declare the variables to contain the color values.
private var red : float;
private var green : float;
private var blue : float;
private var alpha : float;
function Start()
{
// On Start, set the color property values by calling a random-number generating function.
red = RandomColorValue();
green = RandomColorValue();
blue = RandomColorValue();
alpha = RandomColorValue();
gameObject.renderer.material.color = Color(red, green, blue, alpha);
// Print the random color values to the Console.
print(gameObject.renderer.material.color);
}
// Generate a random value between 0.000 and 1.000.
function RandomColorValue() {
var randomValue : float;
randomValue = Random.Range(0.000, 1.000);
return randomValue;
}
 
Search WWH ::




Custom Search