- Home /
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.
Answer by Tehnique · Mar 22, 2015 at 09:15 AM
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);).
Your answer
Follow this Question
Related Questions
Loop a function in c#.HELP!!! 2 Answers
Loop a function 1 Answer
Call function after other objects have run their Start() function 2 Answers
Function being called twice when it shouldn't be 1 Answer
while loop not looping 2 Answers