- Home /
Pause GameLoop with Pause Button
Hi there,
I have a central Manager
class, that starts _GameLoop
function within its Start()
function via InvokeRepeating("_GameLoop", 0, 1);
Now I have another class handling some user input. I have a pause button there. When clicked, I want the gameLoop to pause until the button is being clicked again.
But I have no real clue how. Can you tell me how?
I used InvokeRepeating, so I could count the system time properly, which is needed for calculations later on. But I wonder whether I should have implemented it differently. Maybe with some CoRoutine?
i changed the time parameters of invokeRepeating to 0 and 1/30. just fyi
A popular option otherwise seems to use timescale to pause things. If you still need access to time elapsed etc, you could use Time.realtimesincestartup for that.
Answer by Berkays · Apr 12, 2013 at 02:45 PM
You can use CancelInvoke to stop it and you might control it with a bool inside a coroutine
For example
IEnumerator Routine()
{
if(Paused == false)
{
CancelInvoke(Method);
}
Else
InvokeRepeating(Method);
}
CancelInvoke won't work. Already tried it. The problem is that I have a Button in another class. When clicked CancelInvoke() shall be called. InvokeRepeating is located in the $$anonymous$$anager Class.
Your answer
Follow this Question
Related Questions
Stop Current Coroutine, Then Restart It 1 Answer
How can i loop my animation clip? 2 Answers
Wave Spawning not working 1 Answer
Problem with a Derived Coroutine. 2 Answers
While loop yield lag? 1 Answer