- Home /
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;
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?
Answer by henry96 · Sep 29, 2011 at 01:33 AM
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!
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.
Your answer
Follow this Question
Related Questions
Pause Game When Function Is Enabled? 3 Answers
Unity3D Timer. 1 Answer
How to pause a game? 2 Answers
Timer Pause 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers