coroutine error

Im getting a coroutine error when i try to do a yield WaitForSeconds(15); any help as to how to fix it or why its showing an error would be helped

Show your code. Use the code tag.

var x = 0;
function Update () 
{
	while(x < 11)
	{	print ("hello");
		yield WaitForSeconds(5.0);
		print ("its been five seconds");
		x += 1;
	}
	
}

Update can’t be a coroutine. The point of Update is that it runs every frame.

–Eric

thanks, but now i feel stupid anyhow do i define my own function for it or is there something else you’d recommend

You should move your code into another function and call it from Update using StartCoroutine

Just change Update to Start, since Start can be a coroutine. Also see CoUpdate.

Then you’d have a new instance of the coroutine being called every frame in Update, unless you add logic to prevent that. Update is for stuff that happens every frame; if you don’t want that, there’s no reason to use Update at all.

–Eric