Search Unity

Menu: Deselects when I select hit mouse button. Can no longer navigate using keys afterwards.

Discussion in 'Scripting' started by MikawasakiDigital, Jun 10, 2019.

  1. MikawasakiDigital

    MikawasakiDigital

    Joined:
    Mar 29, 2019
    Posts:
    95
    Hey guys, I'm creating my first menu script. It's the menu you'd get in game for hitting the pause button.

    I've been able to create a menu ui that is navigated using keys.

    Now, not sure if this is a common thing or not but whenever I hit the left mouse button, my options are deselected and I have no way of selecting an option menu again.

    Otherwise I'm free to navigate my menu using my keys.

    Here's why I have down for my code, please feel free to offer any insight on the matter.
    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.     public GameObject pauseMenuUi;
    11.  
    12.     void Update()
    13.     {
    14.         if (Input.GetKeyDown(KeyCode.Tab))
    15.         {
    16.             if (GameIsPaused)
    17.             {
    18.                 Resume();
    19.             }
    20.  
    21.             else
    22.             {
    23.                 Pause();
    24.             }
    25.         }
    26.     }
    27.     void Resume()
    28.     {
    29.         pauseMenuUi.SetActive(false);
    30.         Time.timeScale = 1f;
    31.         GameIsPaused = false;
    32.         Camera.main.GetComponent<PlayerCameraControl>().enabled = true;
    33.     }
    34.  
    35.     void Pause()
    36.     {
    37.         pauseMenuUi.SetActive(true);
    38.         Time.timeScale = 0f;
    39.         GameIsPaused = true;
    40.         Camera.main.GetComponent<PlayerCameraControl>().enabled = false;
    41.     }
    42.  
    43.     public void QuitGame()
    44.     {
    45.         Time.timeScale = 1f;
    46.         SceneManager.LoadScene("MainMenu");
    47.     }
    48. }
    49.