x


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.

more ▼

asked Dec 15 '10 at 11:53 PM

Justin Warner gravatar image

Justin Warner
6.3k 19 27 65

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 16 '10 at 01:07 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

Thank you very much! Didn't know that... Guess that also shows how to keep things to still move (Environment objects).

Dec 16 '10 at 02:14 AM Justin Warner
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x572
x386
x385
x261
x83

asked: Dec 15 '10 at 11:53 PM

Seen: 1685 times

Last Updated: Dec 15 '10 at 11:53 PM