unity – UIElement button doesn’t work when clicked

unity – UIElement button doesn’t work when clicked

[ad_1]

I’ve a small subject with my UI. Each time I click on a button on my pause menu ui nothing occurs even once I hover over the buttons. Nonetheless, in my important menu scene, the UI works with none issues. Evaluating the code facet by facet they’re just about equivalent. I’m additionally utilizing the UI toolkit for my UI as a substitute of the older UI system.

public class PauseMenuUIDocumentManager : MonoBehaviour
{
   non-public static VisualElement pauseMenuContainer;
   non-public Button mainMenuButton;
   non-public Button settingsButton;
   non-public Button quitToDesktopButton;

   public static VisualElement PauseMenuContainer
   {
      get => pauseMenuContainer;
      set => pauseMenuContainer = worth;
   }

   non-public void Begin()
   {
      var root = GetComponent<UIDocument>().rootVisualElement;

      pauseMenuContainer = root.Q<VisualElement>("Background");

      mainMenuButton = root.Q<Button>("MainMenuButton");
      settingsButton = root.Q<Button>("SettingsButton");
      quitToDesktopButton = root.Q<Button>("QuitToDesktop");
      
      mainMenuButton.clicked += MainMenuButtonOnclicked;
      settingsButton.clicked += SettingsButtonOnclicked;
      quitToDesktopButton.clicked += QuitToDesktopButtonOnclicked;

      
   }

   non-public void QuitToDesktopButtonOnclicked()
   {
      Utility.Give up();
   }

   non-public void MainMenuButtonOnclicked()
   {
      Time.timeScale = 1f;
      GameManager.LoadScene("MainMenu");
   }

   non-public void SettingsButtonOnclicked()
   {
      throw new NotImplementedException("This characteristic might be applied later down the road");
   }
}

Right here is my sport supervisor script that really exhibits the pause menu:

if (Enter.GetKeyDown(KeyCode.Escape) && gameIsPaused == false && gameCanBeUnPaused == false)
      {
         PlayerMovement.MovementEnabled = false;
         gameIsPaused = true;
         Time.timeScale = 0f;
         StartCoroutine(CheckIfGameCanBeUnPaused());
         print("The sport is paused");
         OpenPauseMenu();
      }
non-public void OpenPauseMenu()
   {
      PauseMenuUIDocumentManager.PauseMenuContainer.fashion.show = DisplayStyle.Flex;
   }

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply