Changing color (Ignore Yield)

I´m trying to do a small game where balls change color each x seconds.

I set it to change each 5 seconds, for example, so first time it runs color changes to blue and random wait 5 seconds to keep running and change to next value but, next time it finds a value between 0 and 1 yield is ignored. What´s the problem in the code?

var valor : float;
var cambiar : boolean = true;

function Update () {
	
	if(cambiar)
	{
		aleatorio();
	};
	
	if((valor > 0)  (valor < 1))
	{
		Azul();
	};
}

function aleatorio()
{
	
	valor = Random.value * 7;

};

function Azul()
{
	cambiar = false;
	renderer.material.color = Color.blue;
	yield WaitForSeconds(5);
	cambiar = true;
};

you are setting valor to a value between 0 and 1, and then checking continuously in update. Meaning that function is continuously being called. Try this instead: mmm spanish code.

As an aside, I recommend using C#, you’ll find more internet tutorials.

var tiempo : float = 0.0;

function Update(){
   Temporizador();
}
function Temporizador(){
    tiempo += Time.deltaTime;
   if(tiempo > 5){
       Cambiar();
   }
}
function Cambiar(){
    tiempo = 0;
    renderer.material.color = Color.blue; 
}

Double post, sorry about that

Thanks, now it works perfect. Thaknks for the help Brian.