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
1
Question by FPSworrior · Nov 18, 2013 at 05:28 PM · inputpausepausegame

How to pause game.

I want to make a script where if P is pressed down the game will pause and show the gui. I know how to do the GUI part of it but I don't know how to pause.

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

Answer by raycosantana · Nov 18, 2013 at 05:38 PM

To pause use:

this is C#

  if (Input.GetKeyDown("p")){
                 Time.timeScale =0;
                 }

For unpause use Time.timeScale = 1; This has many interesting effect, for example if you use 0.5 instead of 1 you can slow down time.

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 FPSworrior · Nov 19, 2013 at 04:09 PM 0
Share

That's really cool. Thank you for the help.

avatar image spirit_lancer · Dec 21, 2014 at 08:25 PM 0
Share

$$anonymous$$ake sure u don't put this code in fixed update...

avatar image
3

Answer by Sylafrs · Nov 19, 2013 at 04:23 PM

You can also use a static boolean ^^

You could need a menu that uses time to make some effects.. (for example a pause menu with a bar that goes up/down smoothly)

 public static class Utils {
     public static bool Pause = false;
 }
 
 // ...
 
 public class PausableClass {
     public void Update() {
         if(!Utils.Pause) {
             // Do some stuff
         }
     }
 }

There's many cool other ways to do so : for example, Broadcast some messages such as "OnPause" and "OnResume"

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.BroadcastMessage.html

The time scale should be used to slow/accelerate time in order to make some cool effects. Not to pause the game, because its effect is global. You can also use it for Debug purposes..

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 Fornoreason1000 · Jun 07, 2014 at 12:57 PM 0
Share

either works really, personally i have a GUI state the tells the rest of the game when its paused.. which is more or less like this...

avatar image
2

Answer by Pundek · May 29, 2014 at 08:20 PM

//That script works for me C#

public bool CanPause;

 void Start () {
     CanPause = true;
 }
 void Update () {
     if (Input.GetKeyDown (KeyCode.Escape)) {
         if(CanPause)
         {
             Debug.Log("pause");
             Time.timeScale=0;
             CanPause = false;
         }
         else
         {
             Time.timeScale=1;
             CanPause=true;
         }
     }
 }
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 SylafrsOne · Jun 07, 2014 at 11:59 AM 0
Share

Nope. Time scale doesn't really pauses your game. In a game you could use the time scale for other things. You could also need the time scale to be at 1 in your pause menu, so I think that's a bad idea :) A simple boolean must do the trick ^^

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

22 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

Related Questions

Two keys-Same function 1 Answer

How do I pause a method? 1 Answer

Can you make a pause menu have mobile input? 0 Answers

Setting up a menu system and pause screen 1 Answer

Creation of a Pause and a Console Menu? 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