Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by graviton · Oct 01, 2015 at 03:39 PM · timetime.timescalepausingindependent

How do I use Time.unscaledTime?

I know what it does but I'm not sure how to use it in my code All the answers I've found just point to how it's a good way to move or animate when Time.timescale == 0

I need some simple example code

I have 2 moving Cubes, I want one to keep moving when game is paused

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 Fanttum · Oct 01, 2015 at 05:09 PM 0
Share

How are you pausing your game?

avatar image Delivionos · Jul 23, 2019 at 01:40 PM 0
Share

$$anonymous$$ake certain your input detection is within an Update and not a FixedUpdate As the later is bound by timeScale and will not listen to your set of commands.

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by landon912 · Oct 02, 2015 at 12:17 AM

 public class ScaledMoving : MonoBehaviour
 {
     private void Update ()
     {
         //move constantly 5 units per second independent of time scale
         transform.position += transform.position += Vector3.right * 5f * Time.unscaledDeltaTime;
 
         //move 5 units at full time scale; will change depending on setting
         transform.position += transform.position += Vector3.right * 5f * Time.deltaTime;
 
     }
 }

Here is a simple example of how to create a cube moving independent of the frame rate and/or time scale. Delta time is the time since the last frame.

Comment
Add comment · Show 1 · 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
2

Answer by Suddoha · Oct 02, 2015 at 02:04 AM

Just like you'd use Time.deltaTime, here's a short example:

 public class Example : MonoBehaviour {

     // assign these both in the inspector
     public GameObject go1;
     public GameObject go2;
     private bool paused = false;
     
     void Update ()
     {
         if(Input.GetKeyDown(KeyCode.Space))
         {
             paused = !paused;
             Time.timeScale = paused? 0f : 1f;
         }
 
         go1.transform.Rotate(Vector3.up, 30 * Time.deltaTime);
         go2.transform.Rotate(Vector3.up, 30 * Time.unscaledDeltaTime);
     }
 }
Comment
Add comment · 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
0

Answer by outasync · Oct 02, 2015 at 02:02 AM

If you set Time.timescale to 0 then you won't be able to rotate your cube unless you use the animator, simply create your rotating cube animation and set the animator Update Mode to Unscaled time.

Comment
Add comment · Show 1 · 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 Suddoha · Oct 02, 2015 at 02:01 AM 1
Share

That's not true. You can in fact use unscaled time.

avatar image
0

Answer by graviton · Oct 02, 2015 at 08:35 AM

http://forum.unity3d.com/threads/how-do-i-use-time-unscaledtime.358548/#post-2320913

Comment
Add comment · 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

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

33 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 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

Is it possible to change Time.timeScale to a value bigger than 100? 0 Answers

Time hasn't stopped 1 Answer

Trouble with Time.Timescale 2 Answers

Framerate Independent Firing Rate (delta time?) 2 Answers

Time.realTimeSinceStartup behaves weirdly when sending app to background or locking the screen. 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