- Home /
Time.timeScale does nothing
Here is my code...
functrion Update(){
if(Input.GetKeyDown("s")){
if(Time.timeScale == 1.0){
Time.timeScale = 0.1;
print("Time Scale: 0.1");
}
else{
Time.timeScale = 1.0;
print("Time Scale: 1.0");
}
}
}
}
So some odd reason, this isn't working. The tutorial video I'm using has this exact same code and his works. I checked Unity's script refrence page and it suggested using Time.fixedDeltaTime = Time.timeScale with it, this did nothing as well. Infact, the print commands only worked for the first two times and then never again. I heard there was a big change to Time.timeScales behaiver when used with function Update(), but that was mainly with have timeScale set to 0. For me, no value works at all.
The only other code I have is two transform commands to make a cube spin and move, nothing else. So I know there's no other code interferring with this.
Please help?
Can we see the code you are using for movement? If that code is not using Time.deltaTime or Time.fixedDeltaTime, then changing the time scale will not impact movement.
Here's the full code...
function Update () {
transform.Translate(0,0,0.003,Space.World);
transform.Rotate(0,5,0, Space.Self);
if(Input.Get$$anonymous$$eyDown("s")){
print("Current Time Scale: "+Time.timeScale);
if(Time.timeScale == 1.0){
Time.timeScale = 0.1;
print("Time Scale: 0.1");
Time.fixedDeltaTime = Time.timeScale;
}
else{
Time.timeScale = 1.0;
print("Time Scale: 1.0");
Time.fixedDeltaTime = Time.timeScale;
}
}
}
With Time.fixedDeltaTime, I get no addition results. However, making timeScale = 0 does cause the object to stop for a second before continueing again, but only after I've pressed the s key twice. Otherwise, there's no change.
UPDATE: forgot I had collapse on my console turned on, thus why text wasn't appearing again. $$anonymous$$y bad, but the main problem still persists.
Answer by Lasent · Feb 16, 2014 at 05:18 PM
In his video, the code is different than the one you posted. His code:
transform.Translate(0,Time.deltaTime * speed,0);
Since Update gets called every frame, and you change the position by a constant, you won't notice any difference whatsoever by changing Time.timeScale, since Unity's framerate doesn't change much (at least I think). What you have in your code is called framerate-dependant code, since if you increase the framerate, the speed of the object will also increase. That's why they multiply the translation by Time.deltaTime, so that the code will run the same on a low-end and high-end computer the same, making it framerate-independant. Time.timeScale will only have effect on framerate-independant code.
That part I typed into the forum. It's not actually in the code.
Could you link us the tutorial video? The two print commands are possibly because you have the collapse option selected in the debug log, so every Debug.Log goes there. Just untick it, and you should see every time.
It's the walker boys tutorial video. "Unity api part 1 08 4" is the video with the Time.timeScale walkthrough. $$anonymous$$y code is exact to his, but he's getting working results as where $$anonymous$$e fails.
I do have code folding turned on, but that wasn't the problem with the text. I forgot I had Collapse turned on in the unity console. So it was congragating all the prints into two lines. So the text issue is unrelated to my current problem.
I checked it over and did notice he had code I didn't. After investigating for a bit, I realized I had skipped two videos by accident, one of which invole switching the framerate dependancies of objects. After watching of the two, he went over it, I implemented it into my code, and it worked like a charm. Thank you very much, you're a great help.
Your answer
Follow this Question
Related Questions
class List adding to variables are assigning not adding 1 Answer
Script working on some objects but not others 1 Answer
need help with script 1 Answer
Pickup script not workimg 0 Answers
OnGUI not working 1 Answer