- Home /
Question by
superstar123 · Nov 25, 2011 at 07:15 AM ·
updateinvokerepeatingrepeat
Do once when condition is met?
I want my object to do once when condition is met?
var range: float;
function Update()
{
if(range<5)
InvokeRepeating("shoot",3,2); //I want to do this just one time
else
CancelInvoke("shoot"); //If range is >=5, this Invoke will be canceled
}
function shoot()
{
//do something
}
Can someone help me :( thanks in advance!
Comment
Best Answer
Answer by henry96 · Nov 25, 2011 at 08:02 AM
Yes, there is! Boolean (true/false) can solve this one easily.
i.e
var Shoot : boolean = false ;
function Update ( ) {
if (range < 5 ) {
if (Shoot == false ) {
Shoot = true ;
invoke......
}
}
else {
CancelInv.....
Shoot = false;
}
}
I wrote a bit shortcut. But hope u understand. hope it helps!
Your answer
