Hello.
First the problem.
I’m executing a function (triggered by the onMouseDown event) that evaluates if it’s possible to fade the camera background color. (according to the value of a variable). If so, this executes the function “backgroundCambio();”
I’m using lerp for this, and actually it works. But it’s just a little change of color and I understand why is this. The function only executes once (So, it’s not constantly updating itself and it’s not executing itself 60 times per second to make it fade).
When I call the function “backgroundCambio();” inside the update function, it works fine. But I can’t do that because I need to trigger it according to the conditions that I already set up, do the fade between colors and then stop.
Oh yes, I guess this is important… I’m calling the function backgroundCambio(); from another script, in another game object.
Looking the documentation and some forums, I guess that there’s a solution using coroutines, but at the time it has been imposible to me doing it.
Please, help me … I need to execute the fade between colors outside update, because I’m calling the function from outside.
Here’s my script, Thank you so much in advance:
//SETTING THE COLORS I'LL USE
static var colorNivel2: Color = Color(0.75 , 0.22 , 0.16 , 1); //ROJO
static var colorNivel3: Color = Color(0.08 , 0.64 , 0.52 , 1); //VERDE
//MAKING THE Main Camera A STATIC var
static var cam = Camera.main;
function Start () {
//SETTING THIS AS DEFAULT BACKGROUND COLOR
camera.backgroundColor = colorNivel2;
}
//THE FUNCTION
static function backgroundCambio(){
//SETTING TIME
var t : float = Mathf.InverseLerp (0, 5.0, Time.time * 1.9 );
//EXECUTING LERP, MAKING IT FADE
cam.backgroundColor = Color.Lerp ( colorNivel2, colorNivel3, t);
}