Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 PuneetK · Sep 18, 2013 at 10:00 PM · guipausetimescale

Level completed but still playable (timescale problem)

I'm working on a game in which, after you complete a level, a GUI box (called in onGUI) pops up showing you the score, and a few options. That all works great.

The problem here is, when I finish the level, I am still able to move my character around and play as though nothing happened.

The way to fix this which I thought was, that I could add Time.timescale = 0; at the place where I check if you completed the level or no. But this method didn't work, as when the next level is loaded, or when any of the options are chosen, the timescale doesn't return to 1.

I tried putting time.timescale = 1, whenever you click on an option, but still no use.

Here is my code:

 void OnGUI()
     {
         PlayerPrefs.SetInt("levellock" + (currlevel), 1);
         if(levelcomplete)
             {
             Time.timeScale = 0;
             GUI.Box (new Rect (Screen.width*1/8,Screen.height*1/8,Screen.width*3/4,Screen.height*10/14),congobase);
                 
                 //Go to next level
                 if (GUI.Button (new Rect (Screen.width*7/20,Screen.height*3/8 ,Screen.width/3 ,Screen.height/8),gonextLevel)) 
                 {
                     Time.timeScale = 1;
                     Application.LoadLevel(currlevel+1);
                     print("next level");
                 }
             
                 //Go to Level Selection menu
                 if (GUI.Button (new Rect (Screen.width*7/20,Screen.height*4/8 ,Screen.width/3 ,Screen.height/8),golevelSelect)) 
                 {
                     Time.timeScale = 1;
                     Application.LoadLevel(0);
                     print("level select");
                 }
             
                 //Play this level again/Refresh
                 if (GUI.Button (new Rect (Screen.width*7/20,Screen.height*5/8 ,Screen.width/3 ,Screen.height/8),doRefresh)) 
                 {
                     Time.timeScale = 1;
                     Application.LoadLevel(currlevel);
                 }

Basically what I want is, the game to pause when the menu overlay comes up, and the next level to load smoothly as it should load normally.

Comment
Add comment · Show 14
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 gardian06 · Sep 18, 2013 at 10:25 PM 0
Share

is this object marked as [DontDestroyOnLoad()][1]?

if so then does levelcomplete get set to false anywhere?

[1] http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

avatar image ShadoX · Sep 19, 2013 at 07:59 AM 1
Share

Sorry, but why not just disable the player input with a simple bool value , for example?

avatar image PuneetK · Sep 19, 2013 at 12:27 PM 0
Share

@gardian: Its not marked to that, any other ideas? @shadoX: Because it still wont stop the rest of my scene

avatar image DannyB · Sep 19, 2013 at 07:52 PM 0
Share

I agree with @ShadoX - setting timeScale to 0 causes more issues that you need to workaround than it solves. I reserve timeScale = 0 only to my pause menu, and in my next game I will look for other options, as I don't like it even for that.

I would look for other solution - either stopping all the moving parts in the scene (use Send$$anonymous$$essage or C# events or some other broadcast mechanism to notify them) or destroying them.

avatar image PuneetK · Sep 20, 2013 at 01:36 PM 0
Share

Alright guys, got this to work by setting Timescale to 0 on level complete, and changed the first line of code in the level load to timescale = 1. Worked. Want to know if this is a good method or no? And what could be the potential problems with this.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Creating a pause menu (problem using Time.timeScale) 3 Answers

TimeScale Slows down Unity editor 0 Answers

Multiplayer pause menu won't disappear 0 Answers

How to Hide the GUI when time.scale = 1 again 1 Answer

I need to prevent my scroll bar from moving the camera behind the panel 2 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