Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ERPM88 · Feb 16, 2014 at 05:15 PM · timenotworking

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Feb 16, 2014 at 05:20 PM 0
Share

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.

avatar image ERPM88 · Feb 16, 2014 at 06:30 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ERPM88 · Feb 16, 2014 at 06:25 PM 0
Share

That part I typed into the forum. It's not actually in the code.

avatar image Lasent · Feb 16, 2014 at 08:52 PM 0
Share

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.

avatar image ERPM88 · Feb 16, 2014 at 09:56 PM 0
Share

Walker Boy Studios

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.

avatar image Lasent · Feb 16, 2014 at 11:46 PM 0
Share

Edited answer to represent the solution

avatar image ERPM88 · Feb 17, 2014 at 12:28 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges