x


pause timer or player using Time.timeScale

hi guys i have a game manager script that i manage to pause the game when my player collide with an object by using Time.timescale but is there a alternative ways that i can pause only the timesystem and the game continue running if not then pause the game but the timesystem contiune running?

gamemanager.js

function Update(){

//if(isPaused == false){

if(!Paused){

Paused=false; } else {

Time.timeScale = 0;

Paused=true;

}

if(Input.GetButtonUp("Jump")){

Time.timeScale = 1;

Paused=false;

    //starttime = Time.time;

    //time += Time.deltaTime;

    OnGUI();
    }
}

function OnGUI () {

Debug.Log("OnGUI");

var guiTime = Time.time - startTime;

restSeconds = countDownSeconds - (guiTime);

//display messages or whatever here -->do stuff based on your timer
if (restSeconds == 60) {

    print ("One Minute Left");

}
if (restSeconds == 0) {

    print ("Time is Over");

    restSeconds = 0;

    Application.LoadLevel("2");
    //do stuff here
Paused = true;
more ▼

asked Sep 27 '11 at 05:03 PM

halo gravatar image

halo
1 4 6 6

I think you misunderstand timescale. Timescale is the speed that time passes within your game - it is intrinsic to the game itself.

What exactly are you trying to do, and why isn't changing the timescale working for you?

Sep 29 '11 at 12:44 AM Julien.Lynge
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I don't think there is other way to pause the default time system without using Time.timeScale. However, if you make your own time countdown or something else you can pause them. You can make a boolean to check if a pause button is pressed or not. If it is, then stop your script from subtracting the number of time.

if (!isPaused)
{

restSeconds = countDownSeconds - (guiTime);

}

However if you want the game paused but the time continues ticking. Then you can disable all the components that you want to stop except the time by using this line of code

gameObject.GetComponent ("name-of-the-script").enabled = false;

Hope this helps. Good Luck!

more ▼

answered Sep 29 '11 at 01:33 AM

henry96 gravatar image

henry96
597 16 20 23

You can stop all your scripts that way, but be warned that this won't actually pause your game. For instance, if you have any objects with rigidbodies they will continue to move under physics.

Sep 29 '11 at 01:48 AM Julien.Lynge

I agree!!!

Sep 29 '11 at 02:18 AM henry96
(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:

x5070
x572
x347
x261

asked: Sep 27 '11 at 05:03 PM

Seen: 1597 times

Last Updated: Oct 21 '11 at 06:11 AM