# Trigger Button with specific key only

I am having trouble understanding how to trigger a UI button with a specific joystick key only.

Currently i have a pause menu in which i have several buttons. By pressing start i set the game time scale to 0 and activate the menu using this:

void Update()
{
if (Input.GetButtonDown("Submit"))
{
ResumeStartButton();
}
}

public void ResumeStartButton()
{
isPaused = !isPaused;
if (isPaused)
{
pausePanel.SetActive(true);
Time.timeScale = 0f;
usingPausePanel = true;
player.SetActive(false);
}
else
{
pausePanel.SetActive(false);
Debug.Log("Resume game with start button");
Time.timeScale = 1f;
usingPausePanel = false;
player.SetActive(true);
}

}


Once the menu is active, i can navigate through the buttons with the joystick, however the buttons respond only to the "Submit" button i defined earlier.

I tried using this function:

public void Resume()
{
{
isPaused = !isPaused;
if (isPaused)
{
pausePanel.SetActive(true);
Time.timeScale = 0f;
usingPausePanel = true;
player.SetActive(false);
}
else
{
pausePanel.SetActive(false);
Debug.Log("Resume game");
Time.timeScale = 1f;
usingPausePanel = false;
player.SetActive(true);
}
}

}


And call it using an OnClick event on the editor, however it does not work. I have also tried to use onClick on the script directly by creating resumeButton.onClick.AddListener(Test) and by using AddListener:

void Start()
{
isPaused = false;
pausePanel.SetActive(false);
inventoryPanel.SetActive(false);
usingPausePanel = false;

}

public void Test()
{
{
Debug.Log("Do something you donkey!");
}
else
{
Debug.Log("Wrong button");
}
}


However this does not work either: While the menu is active none of the messages appear and when i exit the menu using the start button only the second sentence, "Wrong button" appear.

Can somebody tell me what am i doing wrong? I think that there should be an easy way to solve this with OnClick events but i don't understand what precisely.

For information, I am using the old input manager. I was considering switching to the new system since my project is in still in its beginning.

Any tip will be appreciated!

• So what is calling your Resume()? Are you calling it from Update()? If nothing is ever calling Resume(), how can the check of the buttons inside be called? Jun 19, 2021 at 11:37
• Right now i replaced Resume() with Test() just to see if at least i was able to make it work, but neither Resume() nor Test() did. On top of that, at first i tried to put the line resumeButton.onClick.AddListener(Test); in Update() but it kept being called, that is why i put it in Start().
– FSic
Jun 19, 2021 at 12:24
• It isn't clear but I assume you are using the normal Input Manager and not the new Input system. Do you have a MenuSelect_A assigned in the Input Manager and does it correspond to the button you push on the controller? Or is MenuSelect_A the name of the UI element you expect to be clicked? Jun 24, 2021 at 19:07
• Exactly, I am using the old Input manager. MenuSelect_A is the key I want to use and I assigned it in the Input Manager. Do you think that switching to the new Input system would help with this issue?
– FSic
Jun 25, 2021 at 12:06