This is really just a cute detail I was going to throw on my camera quickly, but it turned into a hurdle - conceptually what I want to do is really simple, but I’m missing something. With the code below, my BG just goes to white and stays there, even though the debug log shows valid RGBA values looping through. I’ve tried both lerping and straight setting the camera Bg color (as commented out below)
Any ideas what I’m getting wrong here?
var bgColor : Color;
var blooping : boolean = true;
function Start () {
StartCoroutine(bgColorShifter());
The color of the background should be updated, unless you’re not actually seeing the background but an object in front of the camera.
Anyway, you’re code isn’t updating correctly. Every second, you pick a new random color (note that Color are between 0 and 1, your random will only create colors like (0,1,0,0) or (1,1,0,1). Then you change the background to 90% of that new color and 10% of the previous color. You should try this :
var bgColor : Color;
var blooping : boolean = true;
function Start () {
StartCoroutine(bgColorShifter());
}
function bgColorShifter()
{
while (blooping)
{
bgColor.r = Random.value; // value is already between 0 and 1
bgColor.g = Random.value;
bgColor.b = Random.value;
bgColor.a = 1.0; // I don't think alpha matters
Debug.Log("bgColor: "+bgColor);
var t: float = 0f
var currentColor = Camera.main.backgroundColor;
while( t < 1.0 )
{
Camera.main.backgroundColor = Color.Lerp(currentColor, bgColor, t );
yield null; // Wait one frame
t += Time.deltaTime;
}
}
}
From the script reference: “Each color component is a floating point value with a range from 0 to 1.” So just use Random.value instead of Random.Range() and you should be fine