Search Unity

Question UI and third person controller problem

Discussion in 'UGUI & TextMesh Pro' started by DomDominator, Mar 22, 2023.

  1. DomDominator

    DomDominator

    Joined:
    Jan 17, 2023
    Posts:
    6
    Hello all

    I created a pause menu using canvas and buttons etc. all tested works fine, however if there is a first or third player controller (I use the ones from the asset store) the cursor does not work on buttons. I tried many thing such as disabling cursor lock, disabling the whole controller prefab with set active but none of this seems to be working. Whenever u press the background the mouse disappears and even if u press escape for it to appear it does not work on any of the buttons. Again buttons work with simple main camera but not with these controllers.

    Mouse just disappears when pressed with third person controller and buttons do not react - without the third/first controller prefab - buttons works fine,

    Any ideas why?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6.  
    7.    
    8. public class PauseMenu : MonoBehaviour
    9. {
    10.    
    11.     public static bool GameIsPaused = false;
    12.     public GameObject pauseMenuUI;
    13.    
    14.    
    15.     // Update is called once per frame
    16.     void Update()
    17.    
    18.     {
    19.         if (Input.GetKeyDown(KeyCode.Escape))
    20.         {
    21.        if (GameIsPaused)
    22.        {
    23.           Resume();
    24.        }
    25.        else
    26.        {
    27.            Pause();
    28.        }
    29.     }
    30.    
    31.     if (Input.GetKeyDown(KeyCode.R)) // restart scene
    32.     {
    33.      SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    34.     }
    35.    
    36.     }
    37.    
    38.    
    39.    
    40.    
    41.    
    42.     void Pause()
    43. {
    44.     pauseMenuUI.SetActive(true);
    45.     Time.timeScale = 0f;
    46.     GameIsPaused = true;
    47.     AudioListener.pause = true;
    48.    
    49. }
    50.  
    51.  
    52. public void Restart()
    53.  
    54. {
    55.      SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    56.      Time.timeScale = 1f;
    57.     GameIsPaused = false;
    58.     AudioListener.pause = false;
    59. }
    60.  
    61. public void Resume()
    62. {
    63.     pauseMenuUI.SetActive(false);
    64.     Time.timeScale = 1f;
    65.     GameIsPaused = false;
    66.     AudioListener.pause = false;
    67.    
    68. }
    69.  
    70. public void LoadMenu()
    71. {
    72.     Time.timeScale = 1f;
    73.     Debug.Log("Loading");
    74.     // for later SceneManager.LoadScene("Menu");
    75. }
    76. public void QuitGame()
    77. {
    78.     Debug.Log("Quit");
    79.     Application.Quit();
    80. }
    81.  
    82.  
    83.  
    84. }
    85.