first function dismiss

Hello,

function NotDamaged()
{
	yield WaitForSeconds(0.3);
	indicateDMG=false;
	for(var i=15; i>0; i--)
	{
		intTimeLeft = i;
		yield WaitForSeconds(1);
	}
	notDamaged=true;
}

OnGUI()
{
        if((!notDamaged) && (intTimeLeft>0))
	{
		GUI.Box(Rect(200, 5, 50, 25), "" + intTimeLeft);
	}
}

I call function NotDamaged each time i am wounded or i cast a spell. And now when this function is called twice or more times intTimeLeft in OnGUI starts changeing from one number to other. What I want to do is somehow kill function NotDamaged which is called first and let continue just for the last called NotDamaged function.
Can someone help? Thanks.

You can do that by using Invoke and CancelInvoke. First use “CancelInvoke” to end all previously invoked functions, and then use invoke to call “NotDamaged” with 0.3 seconds delay (Invoke(“NotDamaged”, 0.3);).