- Home /
Question by
SPIGS · May 12, 2014 at 07:59 PM ·
functionbooleannot workingmethodinvokerepeating
Why is InvokeRepeating not working in boolean method?
I'm trying to kill two birds with one stone by putting some logic in a boolean method. By itself the boolean method does what it's supposed to. The CancelInvoke works as well. However, with the InvokeRepeating there, it doesn't work or return true. I have to manually change the distance to make it true. What is wrong?
float range = 5f; //The Range
private bool InRange () {
if (Vector2.Distance(transform.position, targetPosition) <= range) { //Get Distance
if (!IsInvoking("TheMethod")) { //Incase not invoking
InvokeRepeating("TheMethod", .5f, .5f); //Doesn't work and doesn't return true
}
return true;
} else {
CancelInvoke("TheMethod"); //cancels invoke
return false;
}
}
Comment
Your answer
Follow this Question
Related Questions
Call a function repeatedly while a boolean is true 3 Answers
Walk / Run script not working. 0 Answers
Check a boolean function without using Update() 1 Answer
Waiting for a Function to Complete 1 Answer