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 Dann858 · Jan 18, 2013 at 07:33 PM · menututorialtimescaleworldpausegame

Make game pause on world enter

Hello, I'm new to Unity and C#, well basically scripting in general. So far I've created a little menu that, if I press on New Game, will load the tutorial world. But I want to set the Time.timeScale to 0 directly when the player enters the tutorial world.

My question: How do I make that happen?

Thank you.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Flynn · Jan 18, 2013 at 07:55 PM

Theoretically, setting timesScale to 0 right when you press the New Game button would work (unless you have some kind of crazy cool animation going on), however, if that is not an option, you can try adding this to your C# class:

 public void OnLevelWasLoaded(int level)
 {
     if (level == YOUR_TUTORIAL_SCENE_NUMBER_HERE)
     {
         Time.timeScale = 0;
     }
 }


If you need to wait a few seconds after the scene has loaded (to get the ball rolling), then you can do one of the following:

ONE:

 public void OnLevelWasLoaded(int level)
 {
    //Directly call a Coroutine, allowing you to yield for a number of seconds:
    //(Coroutines are functions that can are excecuted "simultaneously" to other functions (when they yield, other functions continue excecution)
    //This allows you to program in delay, without stopping the rest of your game
    
    if (level == YOUR_TUTORIAL_SCENE_NUMBER_HERE)
    {
            StartCoroutine(OnLevelWasLoaded_Coroutine(level));
    }
 }
 
 public IEnumerator OnLevelWasLoaded_Coroutine(int level)
 {
     
     yield return new WaitForSeconds(10);
     
     
     
     //yield return yields until the following statement (which is in this case new WaitForSeconds()) returns.
     //new WaitForSeconds() causes a pause of the given amount of seconds before returning.
 }

Or, TWO:

 //Unity automatically sees that this is an IENumerator, and starts it as a coroutine without you having to. This is cleaner code, but a bit slower, as we check if this was the correct scene AFTER the coroutine is started, instead of BEFORE.
 public IENumerator OnLevelWasLoaded(int level)
 {  
    if (level == YOUR_TUTORIAL_SCENE_NUMBER_HERE)
    {
            yield return new WaitForSeconds(10);
            StartCoroutine(OnLevelWasLoaded_Coroutine(level));
    }
 }



OnLevelWasLoaded: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html Unity C# Coroutines: http://www.blog.silentkraken.com/2010/01/23/coroutines-in-unity3d-c-version/

Comment
Add comment · Show 2 · 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 Dann858 · Jan 18, 2013 at 09:18 PM 0
Share

And how would I put a timer on this? Let's say I want to explain the player something, and then let the message box dissapear, and start time again. Though I'm probably thinking of adding a button. Where that if the player would click on it, it sets the Time.timeScale = 1.

avatar image Flynn · Jan 18, 2013 at 09:21 PM 0
Share

You can use http://stackoverflow.com/questions/1382597/javas-system-currenttimemillis-or-cs-environment-tickcount to measure the flow of time, ins$$anonymous$$d of Time.time for your GUI animations : D

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

10 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

Related Questions

UI becoming transparent 0 Answers

Zelda like pause menu 1 Answer

Making a pause menu resume 2 Answers

Menu Animated Transition Issues 0 Answers

I'm trying to make a list driven menu for items, skills that meet a interactable interface like the one in Persona 3 Portable, can someone help? 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