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
1
Question by RubbrDuckE · Dec 07, 2014 at 11:58 PM · timetimescaletime.timescale

Unable to change Time.timeScale

I was trying to make a pause menu, which seemed simple enough. However, nomatter what I change Time.timeScale to it instantly reverts it back to 1.. after a while I tried manually changing it under Edit -> Project Settings -> Time, but it automatically reverts it back to 1 there too..

Note: I loaded the script into a different project and it worked perfectly. So it may be an issue with my project settings? They're all just the defaults as far as I'm aware though..

 using UnityEngine;
 using System.Collections;
 
 
 public class PauseMenu : MonoBehaviour {
 
     bool paused = false;
 
     void Update ()
     {
         if ( Input.GetKeyDown( KeyCode.Escape ) )
         {
             Pause();
         }
         Debug.Log ( Time.timeScale );
 
     }
 
     void Pause()
     {
         paused = !paused;
       
         Time.timeScale = 1.0f - Time.timeScale;
     }
   
     void OnGUI()
     {
         if ( paused )
         {
             var rect = new Rect( 10, 10, 100, 30 );
             rect.center = new Vector2( Screen.width/2, Screen.height/2 - 35 );
         
             if ( GUI.Button( rect, "Return to Game" ) )
             {
                 Pause();
             }
           
             rect.center = new Vector2( rect.center.x, rect.center.y + 35 );
           
             if ( GUI.Button( rect, "Quit to Main Menu" ) )
             {
                 // unpause / reset timescale before loading new scene
                 Pause();
                 Application.LoadLevel( "MainMenu" );
             }
         }
     }
 }
 
Comment
Add comment
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

2 Replies

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

Answer by ahmedbenlakhdhar · Dec 08, 2014 at 12:33 AM

You may be changing Time.timeScale value in another script.

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 RubbrDuckE · Dec 08, 2014 at 12:57 AM 1
Share

Yeah, after singling out which script it was I remembered something I changed late last night.. I was changing timescale in an 'else' block that ran every frame (like a dumbass)

avatar image
1

Answer by static_cast · Dec 08, 2014 at 12:04 AM

Time.timeScale = 1f - Time.timeScale;

In your script, you're missing a semicolon after your line. It needs to be there.


Also:

  • You can stop the execution of FixedUpdate() with Time.timescale=0

  • You cannot stop the execution of Update()/LateUpdate(), unless you disable the script.

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 RubbrDuckE · Dec 08, 2014 at 12:21 AM 0
Share

Ah, woops. I fixed that though, and the issue persists

avatar image static_cast · Dec 08, 2014 at 12:27 AM 0
Share
  • You can stop the execution of FixedUpdate() with Time.timescale=0

  • You cannot stop the execution of Update()/LateUpdate(), unless you disable the script.

avatar image static_cast · Dec 08, 2014 at 12:32 AM 0
Share

Typically if you want to pause your game, you just want to disable input and enemy scripts [only in singleplayer]. You could just use if(isPaused()) and have the isPaused() function check some sort of global variable for each script that needs to be paused.

In my game, if you go to the menu, I use if(Screen.lockCursor).

avatar image RubbrDuckE · Dec 08, 2014 at 12:55 AM 0
Share

Ah, that's a good idea as well. Thanks did get it figured out though, ahmedbenlakdhar's suggestion re$$anonymous$$ded me of something I changed last night that was causing the issue..

avatar image static_cast · Dec 08, 2014 at 12:57 AM 0
Share

Well, just to be clear, you will probably have problems with this pause script in the future.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I stop 'timeSinceLevelLoad' without pausing entire game? 2 Answers

2nd independent deltaTime and timeScale variables, or a way to mimic this? 1 Answer

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

Need help affecting 2d jump with UnscaledDeltatime 0 Answers

Pause menu doesn't pause everything 0 Answers


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