- Home /
Pause InvokeRepeating?
Hello. Is there any way to pause InvokeRepeating for a few seconds and then have it continue again? So if a function is being called every 2 seconds, something happens, and it is not called for 4 seconds, and then it starts back up and is called every 2 seconds again. Thanks
Answer by Jason B · Dec 31, 2010 at 07:41 PM
Just a thought, but could you just set your InvokeRepeating to use a variable for the time it takes for it to repeat, and then change the variable as you need to?
For instance, you declare a float called RepeatDelay
or something, and then for your invocation, just do InvokeRepeating("TheThingToRepeat", RepeatDelay)
.
It wouldn't be strictly pausing, but if you set the repeat delay extremely high, you could essentially cause it to "pause" for a few seconds. Not sure how this would all work in practice, but at the moment I can't think of anything wrong with it.
Edit: Oh! Another idea I thought of. Place the entire function you're invoking inside of an if statement that checks if a simple switch is on, perhaps a boolean called InvocationIsPaused or whatever you like. That way it would still be invoked, but it wouldn't do anything if the boolean was false. Plus that way it would strictly keep on the same timing and not miss a beat when it unpauses.
I know this comment is very - Very late, but what does using a variable for repatdelay do in this scenario where you have to pause the invokerepeat, not change its delay time (which can only be set once) ?
None of these ideas answer the question, they don't pause the InvokeRepeating. The first one is completely wrong, the second one is a workaround for some situations but is not an answer.
Your answer
Follow this Question
Related Questions
Invoke Repeating Rate 1 Answer
Invoke repeating limit? 1 Answer
Invoke.Repeating doesn't really "care" about repeat time? 1 Answer
InvokeRepeating affecting parts of script 1 Answer
Is it possible to change Invoke Repeating rate on the fly? 3 Answers