Forum rules - please read before posting.

Changing directly-navigate menus when paused

Hello. I'm trying to add the possibility for the player to choose to navigate menus using the cursor or the keyboard, primarily in the pause menu, but I would also like to make this work in conversations.

What I want is that if the player presses the down key on the keyboard, the menu switches to direct navigation, and the first button is selected. When the player moves the mouse, the menu reverts to cursor use.

I wrote this code and signed the first button as selectedObject:

private void Update()
{
    if (Input.GetAxis("Vertical") != 0)
    {
        KickStarter.menuManager.keyboardControlWhenPaused = true;

        if (EventSystem.current.currentSelectedGameObject == false && selectedObject)
        {
            EventSystem.current.SetSelectedGameObject(selectedObject);
        }
    }

    if (Input.GetAxis("CursorVertical") != 0)
    {
        KickStarter.menuManager.keyboardControlWhenPaused = false;
    }
}

If I start the menu with "directly-navigate menus when paused?" checked in the Menu Manager, the setting changes when I move the mouse, but when I use the keyboard nothing happens, the vertical input is not even recognized.

Is there a solution or some other way to achieve the result I want?

Comments

  • when I use the keyboard nothing happens, the vertical input is not even recognized.

    As in, the Directly-navigate Menus during Conversations? option isn't becoming checked?

    If not, check the value of Input.GetAxis("Vertical") with a Debug.Log statement - AC won't strictly be involved here.

    If the input is being recognised, though: AC has a dedicated function that manually selects the first-found UI Button registered in the Menu Manager

    KickStarter.playerMenus.FindFirstSelectedElement ();
    
  • Thanks for the answer.

    I already tried to get the debug input during the pause menu and it remains 0. I also created a new scene without AC, dragged the menu prefab into it, and tested it, it recognized the input perfectly and my code worked, the button was selected and I could navigate with the arrow keys.

    I thought it was something about the AC operation that was preventing entry.

    So I replaced
    if (Input.GetAxis("Vertical"))
    per
    if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))

    And it worked, although not ideally. I can't get joystick input this way. If you know of a way around this problem, please let me know.

  • It may be down to GetAxis not working while the game is paused.

    Try using GetAxisRaw instead of GetAxis.

  • Thanks a lot, GetAxisRaw worked perfectly. 😄

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.