Cannot Pause Game

I’m having a problem where I pause the game, but it immediately unpauses it. This is in OnGUI(). When I click I only see my mouse blink. When I go to read the console after it says.

Pausing Game
Unpausing Game

if(Input.GetMouseButtonDown(1))
	if(isPaused)
	{
		isPaused = false;
		Time.timeScale = 1;
		Screen.showCursor = false;
		Screen.lockCursor = true;
		print("Unpausing Game");
	}
	else
	{
		isPaused = true;
		Time.timeScale = 0;
		Screen.showCursor = true;
		Screen.lockCursor = false;
		
		print("Pausing Game");
		
		//Bring up screen
	}

Your problem is that OnGUI gets called multiple times per frame - in your case probably an even number :slight_smile:

You shouldn’t use Input.GetMouseButtonDown in OnGUI instead use this:

var e : Event = Event.current;
if(e.button == 0 && e.isMouse){
    ...
}