Search Unity

pause menu restrictions

Discussion in 'Scripting' started by TheCodingNoob, Jan 14, 2020.

  1. TheCodingNoob

    TheCodingNoob

    Joined:
    Jan 10, 2020
    Posts:
    14
    Hi. I watch Brackeye video on how to make menus. but hi did not mention how to make it so my pause menu won't open if my options menu is up. how can I make it so that my pause menu won't open if I am on the options menu?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class PauseMenu : MonoBehaviour
    7. {
    8.     public static bool GameIsPaused = false;
    9.  
    10.  
    11.     public GameObject pauseMenuUI;
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.         if (Input.GetKeyDown(KeyCode.Escape))
    16.         {
    17.             if (GameIsPaused)
    18.             {
    19.                 Resume();
    20.             }else
    21.             {
    22.                 Pause();
    23.             }
    24.         }
    25.  
    26.     }
    27.     public void Resume()
    28.     {
    29.         pauseMenuUI.SetActive(false);
    30.         Time.timeScale = 1f;
    31.         GameIsPaused = false;
    32.     }
    33.  
    34.     void Pause()
    35.     {
    36.         pauseMenuUI.SetActive(true);
    37.         Time.timeScale = 0f;
    38.         GameIsPaused = true;
    39.     }
    40.  
    41.     public void LoadMenu()
    42.     {
    43.         SceneManager.LoadScene(0);
    44.     }
    45.  
    46.     public void QuitGame()
    47.     {
    48.         Debug.Log("Guitting Game..");
    49.         Application.Quit();
    50.     }
    51. }
    52.  
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Audio;
    5.  
    6. public class OptionsMenu : MonoBehaviour
    7. {
    8.     public AudioMixer AudioMixer;
    9.     public void SetVolume (float volume)
    10.     {
    11.         AudioMixer.SetFloat("Volume", volume);
    12.     }
    13.  
    14.     public void SetFullscreen (bool isFullscreen)
    15.     {
    16.         Screen.fullScreen = isFullscreen;
    17.     }
    18. }
    19.