Question by
user_offline · Jan 12, 2016 at 09:19 PM ·
pause game
Pause game on P button
I am working on this one game that needs quick pausing on button press, but all the tutorials I can find are confusing because I am new to unity. Could someone show me a simple pause script with all the code in c# that will pause everything, and continue after the button is pressed again. Thanks.
Comment
Answer by dotfortun3 · Jan 13, 2016 at 03:20 AM
You could try calling: Time.timeScale = 0f;
On Unpause, you would just call: Time.timeScale = 1f;
Adding this for further clarity, you could use a bool to track if the game is paused or not as well, so you would know what to set the timeScale to:
if(_paused)
{
Time.timeScale = 1f;
_paused = false;
}
else
{
Time.timeScale = 0f;
_paused = true;
}