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 NinjaRubberBand · Feb 14, 2014 at 08:17 PM · freezesolutioneasy

Solution to make the game freeze?

I made a game a little bit like flappy bird, with its own original elements. In the start of Flappy bird you need to click the screen to make it start.

In my game, as soon as you press play you need to hold the "bird" up. I want it so everything is paused until i press the mousebutton. A way i see is to go to all scripts and say "all this happen when this happens". But it will take to much time, so i thought there might be a easier way?

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 MachCUBED · Feb 14, 2014 at 08:53 PM

Your problem appears to be similar to pausing and unpausing the game. You can extract the relevant code from the community wiki's PauseMenu script, and I will be reprinting the relevant code here with an explanation:

 private float savedTimeScale;
 
 void PauseGame() {
         savedTimeScale = Time.timeScale;
         Time.timeScale = 0;
         AudioListener.pause = true;
         if (pauseFilter) 
             pauseFilter.enabled = true;
         currentPage = Page.Main;
     }
  
     void UnPauseGame() {
         Time.timeScale = savedTimeScale;
         AudioListener.pause = false;
         if (pauseFilter) 
             pauseFilter.enabled = false;
  
         currentPage = Page.None;
  
         if (IsBeginning() && start != null) {
             start.active = true;
         }
     }

In the above code, Time.timeScale gets set to 0 whenever the game is paused, thereby freezing all action on screen without having to make any calls to any other scripts in the scene. When the game is unpaused, Time.timeScale gets set back to the value saved before pausing (and thus freezing) the game. There are also calls to set the GameObject's AudioListener.pause value to true or false when pausing and unpausing the game, however such calls are only relevant when you want to turn audio on and off as well.

For your purposes, focus on storing Time.timeScale to a private class member, setting Time.timeScale to 0 whenever you want to freeze your action, and then setting Time.timeScale back to your previously-stored value when you want to restart your game's action.

MachCUBED

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

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

Unity freezes when dealing with scripts. 1 Answer

Unity freezes when window inactive - any workaround? 1 Answer

iPhone app hangs in loading screen after upgrade to Xcode 4.0.2 and downgrading back to Xcode 3.5 for Unity 3.3 compatibility 0 Answers

app freezes when iphone keyboard appears 2 Answers

why is my character suddenly move when a scene is loaded? 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