- Home /
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 :(
///////////////////// 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;
}
Answer by Kiwasi · Jul 21, 2014 at 04:01 AM
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;
}
}
thanks for the script @Bored$$anonymous$$ormon! its more efficient :) hmm what do you mean my zombie should rely on time?
my zombie script have a transform.position -= Vector3(0,0.5,0); how can i stop it? :(
What he means is that you should use Time.deltaTime for your zombie movement. Basically: transform.position -= Vector3(0,0.5 * Time.deltaTime,0);
Doing that will mean the zombie will no longer be able to move once you pause because timescale will equal 0, thus Time.deltaTime will equal 0 as well. Now he will have no movement ability in the y axis because it will be set to 0.
Answer by raymanbs · Jul 21, 2014 at 09:30 AM
you can try this in your zombie script:
function Update () {
if (!isPause){
do();
}
else{
//nothing
}
}
function do()
{
//your code
}
You can also check if Time.timeScale == 0 ins$$anonymous$$d.
Follow this Question
Related Questions
transform.position.y and x or z + 1? 0 Answers
Problem with transform 2 Answers
Vector3.Lerp doesn't work! 1 Answer
Moving object with transform.position ignore other objects even if they collided 1 Answer