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 markch25 · Jan 27, 2014 at 02:45 AM · c#androidmenupause

Pause Menu Not Pausing

I was wondering how do I stop processing game events once I hit the pause button? This is for android, I don't know if that makes a difference at all. Thanks in advance!

EDIT: I'm using C#

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vire · Jan 27, 2014 at 02:56 AM

Next time try Google: "unity pause game"

http://answers.unity3d.com/questions/7544/how-do-i-pause-my-game.html http://forum.unity3d.com/threads/18230-Pause-game http://answers.unity3d.com/questions/578156/how-to-pause-game.html http://answers.unity3d.com/questions/249886/time-freeze-pause-game.html

And the list goes on.

http://docs.unity3d.com/Documentation/ScriptReference/Time-timeScale.html

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 andrygames · Jun 19, 2016 at 08:30 PM

@markch25 Add this to the script after the click of the button:

 private bool paused; //when the game is in pause this  become "true"
 private bool clicked; // when the button is clicked this  become "true"
 void Start ()
        {
      paused = false; // at the start, the game is not in pause
     }
 
 void Update () {
         if (clicked == true) 
         {
             paused = !paused; //if paused is true , will become false and the opposite
         }
         if (paused )
                {
             Time.timeScale = 0; //this will stop the game
         } 
         
 else if (!paused ) 
         {
             Time.timeScale = 1;    
         }



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 Dibbie · Jun 19, 2016 at 07:18 AM

Using Time.timeScale you can control automated events that happen in your game, mostly control "Update" functions - for everything else (even using this, some stuff may not be paused, such as AI since that runs on a different system than "Update" at times), you could create a "master script", every other script in the game world will look at that in Update, or any time some type of movement or automated function should happen in your game, it will check this master script for the boolean "isPaused" or something similar, to determine weather or not to continue/carry out its action.

So that might look something like this:

 void Update(){
 if(Input.GetKeyDown(KeyCode.Escape)){
 if(Time.timeScale == 1f){Time.timeScale = 0f;}//pause game
 if(Time.timeScale == 0f){Time.timeScale = 1f;}//unpause game
 }

Which would go on your object you want to trigger pause with - and instead of using the Escape key, you would use whatever method you want to control pause with - on Mobile "Escape" is registered as the phones "Back" button. You could also put this idea with OnFocus, which for a mobile game, may be better - so when they go to read a text message or something outside your game, their screen goes to sleep, etc - itll "pause" the game until they "resume" it.

The other way, is using a "master script" which would just be a script attached to your main camera or an object in the game world you never destroy and every script has easy access to reference, which would just have public bool isPaused = false; then in pretty much every other script, youd surround your entire "Update" function, and any other automated functions with the reference, kind of like: (All code here is untested C#)

void Update(){ if(Camera.main.GetComponent<MasterScript>().isPaused == false){ //your Update code will run here... } }

and

//Example function... void FollowPlayer(Transform player, float speed){ if(Camera.main.GetComponent<MasterScript>().isPaused == false){ //your code here... } }

Since for example, "follow player" would be "automated" because the AI will never stop following the player until certain conditions are met, which may or may not be captured/paused with time.timeScale, at least from my experiences with using that method for pausing all the time.

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

Problems with pause menu displaying items and stopping player movement 2 Answers

How to make a pause menu in c#? 5 Answers

Zelda like pause menu 1 Answer

Creating Pause Game Menu 1 Answer

Trying to make sliding volume bars. 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