- Home /
Couldn't resume once Time.timeScale is set to 0
Beginner here. In my game I have placed a pause method. The best ever method as far as I know to pause is to set Time.timeScale to 0. But the problem is I can't resume by setting it back to 1 as every other object in my game including codes got paused. Someone please help me with a replacement. My code also involves animator gameobjects.
also I want to know whether setting Time.timeScale to 0 would pause the System time Time.time or not.
Thanks in advance. :)
What is the UI system you are using? I'm also placing timescale to 0, but i just have a function in a button and it sets it back to 1. I'm using the new UI that got introduced in Unity 4.6.
UnityEngine's Time.time is affected by Time.deltaTime. I recommend that you use Time.realtimeSinceStartUp if you want Time.time without it being affected by Time.deltaTime.
http://docs.unity3d.com/ScriptReference/Time-realtimeSinceStartup.html
@screenname_taken I just used the pause button as a normal gameobject and not UI button. wouldn't it work then?
@abhishekabz004 nnnoooooooyyysssnnnoooooo? Don't think so, but i guess it will depend on your implementation on the script. If you have something in Update, it won't i think but don't quote me on that :P.
sorry :P btw. I have posted my code in the other answer. help me out if you find any mistake :)
Answer by sabish-m · Jun 12, 2015 at 06:06 PM
#pragma strict
function Paused(){
Time.timeScale = 0.0;
}
function Resume(){
Time.timeScale = 1.0;
}
function Quit(){
Application.Quit();
}
I appreciate your help. :) But I already have my code. Its just that it is not working (resu$$anonymous$$g) once it gets paused. Here is my code.
public class pauseaction : $$anonymous$$onoBehaviour {
public bool ispause= true;
void Update () {
if (Time.timeScale == 0) {
//Time.timeScale =1;
/* I even tried to change it this way. But still it wouldnt change once it got paused */
}
}
void On$$anonymous$$ouseDown(){
if (ispause) {
ispause=false;
Time.timeScale=0;
} else {
ispause=true;
Time.timeScale = 1;
}
}
}
Correct me if I made some mistake. Thank you once again for helping me. :)
Your answer
Follow this Question
Related Questions
Pause game that not using deltatime for movment 1 Answer
Pause Game When Function Is Enabled? 3 Answers
Stop force from being applied during pausescreen 1 Answer
Can't set Time.timeScale back to 1. 2 Answers
Distribute terrain in zones 3 Answers