Search Unity

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

Discussion in 'Editor & General Support' 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. public class PauseMenu : MonoBehaviour
    6. {
    7.     public static bool GameIsPaused = false;
    8.     public GameObject pauseMenuUi;
    9.     void Update()
    10.     {
    11.         if (Input.GetKeyDown(KeyCode.Tab))
    12.         {
    13.             if (GameIsPaused)
    14.             {
    15.                 Resume();
    16.             }
    17.             else
    18.             {
    19.                 Pause();
    20.             }
    21.         }
    22.     }
    23.     void Resume()
    24.     {
    25.         pauseMenuUi.SetActive(false);
    26.         Time.timeScale = 1f;
    27.         GameIsPaused = false;
    28.         Camera.main.GetComponent<PlayerCameraControl>().enabled = true;
    29.     }
    30.     void Pause()
    31.     {
    32.         pauseMenuUi.SetActive(true);
    33.         Time.timeScale = 0f;
    34.         GameIsPaused = true;
    35.         Camera.main.GetComponent<PlayerCameraControl>().enabled = false;
    36.     }
    37.     public void QuitGame()
    38.     {
    39.         Time.timeScale = 1f;
    40.         SceneManager.LoadScene("MainMenu");
    41.     }
    42. }
    43.