Pause button

I am trying to make a button (LeftAlt) that will set the timeScale to 0 and show/unlock the cursor but my script isn’t working, here is my script (JavaScript):

var p = 0;
function Update () {
if (Input.GetKeyDown(KeyCode.LeftAlt) && p == 0)
{
Time.timeScale=0;
Screen.showCursor = true;
Screen.lockCursor = false;
p = 1;
}
if (Input.GetKeyDown(KeyCode.LeftAlt) && p == 1)
{
Time.timeScale=1.0;
p=0;
}

}

p = 1;
}
if (Input.GetKeyDown(KeyCode.LeftAlt) && p == 1)

That’s going to set p to 1 then check that p == 1

var p = 0;
function Update () {
if (Input.GetKeyDown(KeyCode.LeftAlt))
{
  if (p == 0)
  {
   Time.timeScale=0;
   Screen.showCursor = true;
   Screen.lockCursor = false;
   p = 1;
  }
  else
  {
   Time.timeScale=1.0;
   p=0;
  }

}

EditorApplication.isPlaying = false;