Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Sici9 · Jun 22, 2021 at 09:18 PM · uiinputjoystickbutton trigger events

Why can't I use the other buttons in the UI menu?

Hi everyone! I am having an hard time understanding how to properly set the UI buttons of a Pause menu for use with a Joystick. My goal is simply to:

  1. Stop the game and enter the pause menu by clicking the 'start' key on the joystick;

  2. Navigate through the menu with the joystick;

  3. Trigger the proper function associated to each UI button with another joystick key, say 'A';

  4. Resuming the game either by pressing again on the 'start' key or by pressing on the 'Resume' button with another joystick key, say 'A' (just like it is done in almost any game supporting joysticks)

So far, I managed to do point 1 and 2, however, when it comes to the rest I encounter the following problems:

  • Only the first function within the Update() method is called, regardless of the button I am pressing with the 'A' key,

  • The other buttons work but only if I press the 'start' key,

Here below is my current script:

 public class PauseMenu : MonoBehaviour
 {
     private bool isPaused = false;
     public GameObject pausePanel;
     public GameObject inventoryPanel;
     public Button resumeButton, mainMenuButton, inventoryButton, SaveButton;
     
 
     public GameObject player;
     public bool usingPausePanel;
     public string scene2Load;
     void Start()
     {
         //Set-up pause and inventory menus to inactive as game starts
         isPaused = false;
         pausePanel.SetActive(false);
         inventoryPanel.SetActive(false);
         usingPausePanel = false;
 
         //Add listeners to button click events
         resumeButton.onClick.AddListener(Resume);
         mainMenuButton.onClick.AddListener(Quit2Main);
         inventoryButton.onClick.AddListener(SwitchPanels);
         
     }
 
     void Update()
     {
         if (Input.GetButtonDown("Submit"))
         {
             ResumeStartButton();
         }
         else if (isPaused)
         {
             if (Input.GetButtonDown("MenuSelect_A") && resumeButton.onClick != null)
             {
                 Debug.Log("Resume");
                 Resume();
                 resumeButton.onClick.RemoveAllListeners();
             }
             else if (Input.GetButtonDown("MenuSelect_A") && mainMenuButton.onClick != null)
             {
                 Debug.Log("Q2M");
                 Quit2Main();
             }
             else if (Input.GetButtonDown("MenuSelect_A") && inventoryButton.onClick != null)
             {
                 Debug.Log("Inventory");
                 SwitchPanels();
             }
         }
     }
 
     public void Resume()
     {
         if (isPaused)
         {
             pausePanel.SetActive(false);
             Time.timeScale = 1f;
             usingPausePanel = false;
             player.SetActive(true);
             Debug.Log("In resume");
 
         }
     }
     public void ResumeStartButton()
     {
         isPaused = !isPaused;
         if (isPaused)
         {
             pausePanel.SetActive(true);
             Time.timeScale = 0f;
             usingPausePanel = true;
             player.SetActive(false);
             Debug.Log("In resumeStart");
         }
         else
         {
             pausePanel.SetActive(false);
             Debug.Log("Resume game with start button");
             Time.timeScale = 1f;
             usingPausePanel = false;
             player.SetActive(true);
         }
 
     }
 
     public void Quit2Main()
     {
         SceneManager.LoadScene(scene2Load);
         Time.timeScale = 1f;
         Debug.Log("In Q2M");
     }
 

First question:

  1. I guess that the reason why only the first function that i want to call with the 'A' key (i.e. Resume() in my case) gets called is because whenever i press the A key the if statement will always result true, since in the Start() method I added a listener associated to each button. How can i detect that a specific button has been clicked and not another one? I was looking for something like xxxButton.onClick.IsInvoking() but that does not seem to exist;

  2. Why do the button works with the 'Start' key instead?

Thanks in advance for the help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Proliecan · Jun 23, 2021 at 10:00 AM

Here is a great Tutorial by Thomas Brush regarding exactly your goal:

Thomas Brush - Make A Gorgeous Start Menu (YouTube)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sici9 · Jun 23, 2021 at 04:58 PM 0
Share

Thanks for the link! However I saw this tutorial already and it does not talk much about handling the inputs. For what it's worth, my menu has the same functionalities as his, but it only works with the 'start' key i.e. the one i use to activate the menu. Once in the menu, I would prefer to use another key e.g. 'A' on the joystick.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

228 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using Right Joystick to Select Weapon in Weapon Wheel 1 Answer

Lock OnScreenStick to just the Y axis. 0 Answers

UI: Execute action instead of "Navigation" 0 Answers

Add different input for On Click event (UI) 0 Answers

How to get input from wheel(car direction) joystick? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges