Search Unity

Pausing game/Slowing it down in background of pause screen

Discussion in 'Scripting' started by BubyMB, Dec 28, 2016.

  1. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Hey guys, I am doing a little project and was just wondering if/how I can pause a game behind a pause screen.

    This is my interaction menu so far;
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class InteractionMenu : MonoBehaviour {
    6.  
    7.     private bool pressed;
    8.  
    9.     private bool EscapeMenu;
    10.     private bool Inventory;
    11.     private bool Chat;
    12.  
    13.     public GameObject EscapeMenuObj;
    14.     //public GameObject InventoryObj;
    15.     //public GameObject ChatObj;
    16.  
    17.     void Start () {
    18.         pressed = false;
    19.         EscapeMenu = false;
    20.         Inventory = false;
    21.         Chat = false;
    22.     }
    23.  
    24.     void Update () {
    25.  
    26.         //Escape Menu
    27.         if (Input.GetKey (KeyCode.Escape)) {
    28.             if (!pressed) {
    29.                 pressed = true;
    30.                 if (!EscapeMenu) {
    31.                     CursorLock ("Off");
    32.                     EscapeMenu = true;
    33.                     EscapeMenuObj.SetActive (true);
    34.                 } else {
    35.                     CursorLock ("On");
    36.                     EscapeMenu = false;
    37.                     EscapeMenuObj.SetActive (false);
    38.                 }
    39.             }
    40.         } else {
    41.             pressed = false;
    42.         }
    43.  
    44.         //Inventory
    45.         if (Input.GetKey (KeyCode.E)) {
    46.             if (!Inventory) {
    47.                 CursorLock ("Off");
    48.                 Inventory = true;
    49.                 //InventoryObj.enabled = true;
    50.             } else {
    51.                 CursorLock ("On");
    52.                 Inventory = false;
    53.                 //InventoryObj.enabled = false;
    54.             }
    55.         }
    56.  
    57.         //Chat
    58.         if (Input.GetKey (KeyCode.T)) {
    59.             if (!Chat) {
    60.                 CursorLock ("Off");
    61.                 Chat = true;
    62.                 //ChatObj.enabled = true;
    63.             } else {
    64.                 CursorLock ("On");
    65.                 Chat = false;
    66.                 //ChatObj.enabled = false;
    67.             }
    68.         }
    69.     }
    70.  
    71.     void CursorLock(string Switch){
    72.         if (Switch == "On") {
    73.             Cursor.visible = false;
    74.             Screen.lockCursor = true;
    75.         } else {
    76.             Cursor.visible = true;
    77.             Screen.lockCursor = false;  
    78.         }
    79.     }
    80.        
    81. }
    82.  
    83.  
     
  2. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    You have not shown your game's script at all, but assuming all your moving stuff moves with reference to Time.deltaTime, you can adjust the game's timescale from the default 1 to maybe 0.2 to slomo everything moving.
     
    TaleOf4Gamers likes this.
  3. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Not sure if theres an easier/better way but thats how I do it most of the time.
     
  4. BubyMB

    BubyMB

    Joined:
    Jun 6, 2016
    Posts:
    140
    Yeah, worked just as i needed it to, thanks