I have a script where I use InvokeRepeating, and if the play gets too close to a object it stops, but if the player gets out of the range again it wont update and continue the InvokeRepeating. How can I fix this?
you cancel the Invoke but you don’t Invoke next time so it remains Not Invoked
var isInInvoke : boolean = true;
function Update(){
if(Vector2.Distance(transform.position, player.position) < distance){
CloseEnough = true;
} else {
CloseEnough = false;
}
if (CloseEnough == true) {
CancelInvoke("Spawn");
isInInvoke=false;
}
if (CloseEnough == false && isInInvoke==false) {
InvokeRepeating ("Spawn", this.spawnTime, this.spawnTime);
isInInvoke=true;
}
}