pause game

Help!!!

I want to pause my game when after i click the mouse.
i can’t get it right.

Here’s my code:

#pragma strict

private var guiOn = false;
var wasClicked : boolean;
var paused : boolean = false;
     
function OnMouseDown()
{
    wasClicked = true;
	OnPausedGame();
    Activate();
}
     

function OnMouseEnter()
{
    if (wasClicked) 
    {
    	Activate();
    }
}

function Activate()
{
	guiOn = true;
	OnPausedGame();
    //OnGUI();
}

function OnGUI()
{
	if (guiOn)
    GUI.Box(new Rect(0, Screen.height - 50, 300, 100), "test");
}

function OnPausedGame()
{
	if (wasClicked)
	{
		if (!paused)
		{
			Time. timeScale = 0;
			paused = true;
			
			OnGUI();
		}
	}
}

To pause a game you could simply write

function Update()
{
    if(Input.GetButtonDown("Fire1") && Time.timeScale != 0)
    {
        Time.timeScale = 0;
    }
    else
    {
        Time.timeScale = 1;
    }
}

This is a basic example of pausing. Your code seems somewhat excessive but then again I don’t know how your program works.

Can I ask another question?

How can i put an if statement to GUI.button?