Time.timescale problems

Hello i have a javascript where i can pause my game but it seems not to work, i can unpause but not pause again. If you can tell what the problem is throught the script then tell me thanks (:

#pragma strict

var isPaused : boolean = false;

function Update ()
{
	//Pause
	if(Input.GetKeyDown(KeyCode.P) && isPaused == false)
	{
		isPaused = true;
	}
	
	//UnPause
	if(Input.GetKeyDown(KeyCode.P) && isPaused == true)
	{
		isPaused = false;
	}
	
	//Pause
	if(isPaused == true)
	{
		Time.timeScale = 0.0;
	}
	
	if(isPaused == false)
	{
		Time.timeScale = 1.0;
	}
}

Your code is probably getting caught in the unpause check. Because everything in the Update() function happens in the same frame, if you press “P” and then set isPaused to true, when it gets to the next line, “P” is still pressed, and isPaused is now also true, so it sets it to false. You’d be better off putting it in an if statement.

void Update()
{
   if(Input.GetKeyDown(KeyCode.P))
   {
      isPaused = !isPaused;

      if(isPaused)
         Time.timeScale = 0.0f;
     else
         Time.timeScale = 1.0f;
  }