yield WaitForseconds not working?

HI,

my code below doesn’t seem to wait for 5 seconds before executing the code

var gameState : String;
var circleColor : int;

function Start () {
	Debug.Log("The game has started");
	gameState = "play";
}

function Update () {
	WaitFor_Seconds(5);
	ChangeCircleColor();
}

function ChangeCircleColor () {
	if(gameState == "play") {
		circleColor = Random.Range(1,5);
		if(circleColor >= 2) {
			gameObject.GetComponent.<Renderer>().material.color = Color.green;
		}
		else {
			gameObject.GetComponent.<Renderer>().material.color = Color.red;
		}
	}
}

function WaitFor_Seconds(time) {
	yield WaitForSeconds (time);
}

Tnx Adam

Hello, Adam!

You cannot use WaitForSeconds in Update, because Update is called every frame.
Please write something like this:

    function Start () 
   {
         Debug.Log("The game has started");
         gameState = "play";
         WaitFor_Seconds(5);
         ChangeCircleColor();
     }

P.S. Almost similar Q: Execute coroutine in Update() - Questions & Answers - Unity Discussions