- Home /
How can I call InvokeRepeating wich can be found in the start function, after I Cancelled the Invoke?
At he moment Im making a starship game, and I making a boss battle, and when the boss comes I have to stop the InvokeRepeating wich counts the travelled distance. My problem is, when I Cancel the InvokeRepeating I can't restart it from another function because the function belongs to the Update function.
Thank you for your help guys!
Answer by Link17x · Mar 15, 2020 at 12:19 AM
You shouldn't have the InvokeRepeating method in the Update method. "InvokeRepeating" is constantly calling a method, so you don't need Update to constantly tell InvokeRepeating to constantly call a method (hope that makes sense :D)
So basically you want to have a method like
public void StartCountDistanceTravelled()
{
InvokeRepeating(CallSomeMethod);
}
public void CancelCountDistanceTravelled()
{
CancelInvoke();
}
Then you can call these methods from whichever script. Use cancel to stop it, then start it when you want it to start calling that method again. If you don't need to call these methods from another script, then make them private.
Your answer
Follow this Question
Related Questions
Loop a function, once per second, X number of times 1 Answer
Raycast ignoring InvokeRepeating intervals 0 Answers
Issue with starting/canceling invokes 0 Answers
Call a function repeatedly while a boolean is true 3 Answers
InvokeRepeating couldn't be called for a function inside an instanced object 1 Answer