I am trying to make a platform runner in 3D and wanted to be able to pause the game when the user pressed “P”. I was able to do this but now I’m having a problem with resuming the game. I tried setting the Time.timeScale back to 1, but it didn’t work. I’m using this code:
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public bool paused = false;
void Pause()
{
Time.timeScale = 0;
}
void Update()
{
if(Input.GetKey("p"))
{
if(paused == false)
{
Pause();
}else
{
paused = false;
Time.timeScale = 1;
}
}
while(paused)
{
Pause();
}
}
}
I have tried to disable the forces on the Rigidbody, but I had the same problem.
I hope someone can help me and thanks in advance.