hi everyone, i have a problem in my pause script, when i press the pause button my zombie is still moving . can anyone help me :(

29466-zombiee.png

///////////////////// Pause Script/////////////////////////

#pragma strict
//private var zombies;
var count : int =2;
function Start () {
	
//zombies=GameObject.FindGameObjectsWithTag("zombie");
}

function Update () {
if(count==2)
{
Time.timeScale=1;
//zombies.GetComponent.<movement>().Go();
}
if(count==1)
{
Time.timeScale=0;
//zombies.GetComponent.<movement>().Stop();
}
if(count==0)

{

Reset();
}

}
function Reset()
{
count=2;

}
function OnMouseDown()
{
	Debug.Log("Paused!");
	count-=1;

}

That’s the wackiest way I’ve ever seen to write a pause script. Everything in the zombie script should rely on time. This means that the zombie will stop without any other interaction when timescale = 0

Here’s a more efficient way to code it. You can delete everything else from the script.

var isPaused : bool = false;

function OnMouseDown()
{
    isPaused = !isPaused;
    if(isPaused){
        Time.timeScale = 0;
    } else {
        Time.timeScale = 1;
    }
}

you can try this in your zombie script:

function Update () {
     if (!isPause){
         do();
    }
    else{
     //nothing
    }
}
function do()
{
    //your code
}