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 :frowning: thanks in advance!

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!