How to make a pause function?

How can I make a pause function that when a pause button is pressed, the game stops.

Do I really need to disable everything from every game object or is there an easier way to just stop everything?

var isPaused : boolean = false;

function Update()
{
if(Input.GetKeyDown("p"))
{
Pause();
}
}

When the P key is pressed it will try to run the Pause function. So, make a pause function.

function Pause()
{
if (isPaused == true)
{
Time.timeScale = 1;
isPaused = false;
}
else
{
Time.timeScale = 0;
isPaused = true;
}

That, i think, should work. Not tested or anything but the worst that can happen is that someone else will correct me =)

Fx:

function Update ()
{
if(Input.GetKeyDown("p"))
   {
   Time.timeScale = 0;
   }
}

When the "P" key is pressed the game pauses. When you want to "Unpause" it just use:

Time.timeScale = 1;

Hope this helped :)

Try using this.

function Update () {
     if (Input.GetKeyDown(KeyCode.P)) {
          isPaused = !isPaused;
     }
     Time.timeScale = isPaused ? 0 : 1;
}