- Home /
 
How to Pause game
Hello!. In my 3d Game i have a panel which is the one you see when the game loads. I have this as the panel you use to play the game. But one question how do i make an if statement where if the game panel PanelStart is active then the TimeScale= 0 ? here is my script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class Play : MonoBehaviour
 {
 
     
 
     public GameObject PanelStart;
 
    void Paused ()
     {
 
     }
 
     public void Start()
         {
             PanelStart.SetActive(false);
             Time.timeScale = 1;
         }
     }
 
 
              Answer by Cornelis-de-Jager · Sep 01, 2019 at 09:08 PM
You have to design a game manager from the ground up.
 public class GameManager : MonobBehaviour {
     pubic enum GameState {
         MainMenu,
         Running,
         Paused
         
     }
     
     public GameState gameState = GameState.MainMenu;
     
     pubic void Update () {
     
         
         if (Input.GetKeyDown(KeyCode.P)) {
             if (gameState == GameState.Paused;)
                 gameState = GameState.Running;
             else 
                 gameState = GameState.Paused;
         } 
         
         
         switch (gameState) {
             case (GameState.MainMenu):
                 // DO things
                 break;
                 
             case (GameState.Running):
                 // Enable all relevant objects
                 break;
                 
             case (GameState.Paused):
                 // Disbale all relevant objext
                 break;
         }
     }
 }
 
              I'm designing for mobile and have a button to play, is there a way to make it a function of the void in my code to set time to 0.00f when panel is active
Your answer
 
             Follow this Question
Related Questions
Pause menu... Isn't pausing everything... 1 Answer
Couldn't resume once Time.timeScale is set to 0 1 Answer
How to Appease a pause menu in a game that changes it's time scale? 1 Answer
TimeScale = 0 crashes Unity 1 Answer
Pause, Unpause 1 Answer