Skip to main content
Note specifying I am using the old input system
Source Link
FSic
  • 188
  • 13

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!

Any tip will be appreciated!

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!

Source Link
FSic
  • 188
  • 13

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()
    {
        if (Input.GetButtonDown("MenuSelect_A")) 
        { 
                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;


        resumeButton.onClick.AddListener(Test);


    }

public void Test() 
    {
        if (Input.GetButtonDown("MenuSelect_A"))
        {
            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.

Any tip will be appreciated!