- Home /
Pause menu... Isn't pausing everything...
//This is the code that wont stop executing.... var Monster : GameObject[]; function Start() { for ( var i = 0; i < Monster.length; i++ ) { Instantiate ( Monster[i], transform.position, transform.rotation ); yield WaitForSeconds ( 2 ); } }
//This is the move script: var target : Transform; var speed = 0.0f; var times = 0;
function Update () {
if(!target)
{
target = GameObject.FindWithTag("House").transform;
}
var targetRotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 100);
if(times == 0)
{
speed = speed/2;
times++;
}
transform.Translate(0, 0, speed);
}
//This is my pause script: var savedTimeScale;
function Update() { if ( Input.GetKeyDown ( "escape" ) && Time.timeScale == 0 ) { UnPauseGame(); }
if ( Input.GetKeyDown ( "escape" ) && Time.timeScale != 0 )
{
PauseGame();
}
}
function PauseGame() { savedTimeScale = Time.timeScale; Time.timeScale = 0; AudioListener.pause = true; print ( "Paused" );
//Show the picture.
}
function UnPauseGame() { Time.timeScale = savedTimeScale; AudioListener.pause = false; print ( "UnPaused" );
//Take away the picutre.
}
The "Monsters" that are made keep moving.
Answer by Statement · Dec 16, 2010 at 01:07 AM
Pause menu Isnt pausing everything
The "Monsters" that are made keep moving.
transform.Translate(0, 0, speed);
You don't include delta time.
When timeScale is set to zero the game is basically paused if all your functions are frame rate independent.
transform.Translate(0, 0, speed * Time.deltaTime);
Update is still getting called regardless of Time.timeScale (FixedUpdate is not). Maybe you want to make an early return in case timeScale is 0.
If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.
Thank you very much! Didn't know that... Guess that also shows how to keep things to still move (Environment objects).
Your answer
Follow this Question
Related Questions
How to Appease a pause menu in a game that changes it's time scale? 1 Answer
Pause menu doesn't pause everything 0 Answers
Pause Menu Problem 1 Answer
TimeScale = 0 crashes Unity 1 Answer
Pause, Unpause 1 Answer