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 Alieos · Jun 19, 2014 at 01:36 AM · c#pause gamescrptinggamedesign

Pause game without using timeScale

Hi all,

As the title suggests, is there are simple way to pause a game without using Time.timeScale? I haven't decided on how I want the pause functionality will work in my game, but I can see problems I may run into if I use the "timeScale" method.

What are other ways to pausing a game?

Pls try to give examples in C#.


Thank you in advance for your help.

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
7
Best Answer

Answer by ninjapretzel · Jun 19, 2014 at 02:08 AM

With Unity 4.5, it is possible to use Time.timeScale, because there is also Time.unscaledDeltaTime and Time.unscaledTime for objects that don't need to get paused. This is probably the easiest solution, since you don't need to test for extra conditions like with the other solutions.

The other solutions would be to have a static 'paused' boolean somewhere (like make a static class Game, so it would be Game.paused), and either wrap all neccessary Update function code in an 'if (!Game.paused)', or add a behaviour to objects that disables other behaviours when Game.paused is true, and enables them when Game.paused is false.

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 fcl910910 · Aug 19, 2018 at 05:57 AM 0
Share

Wow, really thank you. I was looking for a solution and I didn't know there is unscaledDeltaTime to use.

avatar image
-1

Answer by DangerPenguin · Jun 20, 2014 at 06:01 AM

NOTE:: My way of solving this should only work for simpler 2D games that don't heavily rely on the physics engine! Use at your own risk, ymmv.

I usually solve this with a global variable(or a singleton) for whether the game is paused or not, and then in any object the uses its update function to "act", I check if the game is paused before I let it do anything.

Here's some Code.

You need to make a script to hold all your global variables, (mine is GlobalVariables.js) and attach it to some object that will always be in your scene (like an empty object JUST for this).

 #pragma strict
 
 static var isPaused : boolean;
 
 function Start () {
     isPaused = false;
 }

Attach this to the empty object in your scene.

Now, inside of ANY object that has to "act", change its update function to look like this.

 function Update () {
     if(!GlobalVariables.isPaused ){
         //All your old code/update code goes in here!
     }
 }
 

And voila, your game doesn't do anything when you set GlobalVariables.isPaused to true, but anything inside of OnMouseDown functions will still fire!

EDIT:: fixing words

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 tapir · Jun 19, 2014 at 02:06 AM

You can use events for that. You can create an event manager that will call the function Pause() then you click a button. In your scripts you can create a function OnPause() and suscribe it to the event manager. Inside the OnPause() function you can handle the pausing logic for each script.

This is a great tutorial for events! Hope it helps.

Unity - Events

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

what is wrong whis this? 1 Answer

Where can I find C# tutorials for a absolute beginner? 7 Answers

Crash the entire game 3 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