top of page
Search

Main Menu and Pause Menu

  • Writer: Keshav Batra
    Keshav Batra
  • Feb 17, 2023
  • 1 min read

I've finally finished my pause menu and main menu after some crashes from my computer. I made the transitions happen by using scene management in the scripts for the menus.



Here is the code:



For the Pause Menu

public class PauseMenu : MonoBehaviour
{

    public GameObject pausemenu;
    public static bool IsPaused;
    // Start is called before the first frame update
    void Start()
    {
        pausemenu.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            if (IsPaused)
            {
                ResumeGame();
            }

            else
            {
                PauseGame();
            }
        }
    }

    public void PauseGame()
    {
        pausemenu.SetActive(true);
        Time.timeScale = 0f;
        IsPaused = true;
    }

    public void ResumeGame()
    {
        pausemenu.SetActive(false);
        Time.timeScale = 1f;
        IsPaused = false;
    }

    public void GoToMainMenu()
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene("MainMenu");
    }

    public void QuitGame()
    {
        Application.Quit();
    }
}

For the pause menu

{
    public void PlayGame()
    {
        SceneManager.LoadScene(1);
    }

    public void QuitGame()
    {
        Application.Quit();
    }
}

 
 
 

Комментарии


bottom of page