• 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, t$$anonymous$$s isn't working. The tutorial video I'm using has t$$anonymous$$s exact same code and $$anonymous$$s works. I checked Unity's script refrence page and it suggested using Time.fixedDeltaTime = Time.timeScale with it, t$$anonymous$$s did not$$anonymous$$ng 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, not$$anonymous$$ng else. So I know there's no other code interferring with t$$anonymous$$s.

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.GetKeyDown("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. My 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 $$anonymous$$s 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 t$$anonymous$$nk). 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 $$anonymous$$gh-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. My code is exact to his, but he's getting working results as where mine 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Jump Script, no luck getting it to work.. 2 Answers

OnSerializenetworkView not doing anything?? 1 Answer

Walking script not working need help 1 Answer

Unity shadows work in scene, but no through camera 0 Answers

Mouse won't lock 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