Skip to main content
Add info following first response.
Source Link
FSic
  • 188
  • 13

EDIT:

Following on the answer by @Kevin, I managed to activate/deactivate the menu. What i intended to do initially, however, was to do so by pressing the same key, like pressing the start button to show up the screen and again, which is why I thought of creating 2 different ActionMaps, so that one would have the action pause and the other the action unpause using the same key. As it is now, the scripts calls the 2 actions at once. I tried again to disable and enable the but without results. I guess that if i disable/enable the gamecontroller, i do it for all of its action maps, is that right? Is there a workaround?

EDIT:

Following on the answer by @Kevin, I managed to activate/deactivate the menu. What i intended to do initially, however, was to do so by pressing the same key, like pressing the start button to show up the screen and again, which is why I thought of creating 2 different ActionMaps, so that one would have the action pause and the other the action unpause using the same key. As it is now, the scripts calls the 2 actions at once. I tried again to disable and enable the but without results. I guess that if i disable/enable the gamecontroller, i do it for all of its action maps, is that right? Is there a workaround?

Don't repeat tags in the title
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Unity UI: Menu not disappearing after input

I am having some issues with the UI and the Input system. What I am trying to do is "simply" to make a menu appear and disappear upon pressing a certain key. To do so, iI created an animator attached to the Menu canvas, to which I attached the following script:

The idea is that when iI press the pause key (mapped in the actionMapActionMap of the player i.e. in game-game), the menu will be activated, the animation triggered in order to pass to the state transition 'menu activated', the in game ActionMap is disabled and the menu ActionMap enabled. Viceversa

Vice versa, if the menu is already active, (anim.GetBool("isPaused") == true), iI will go the other way around.

So far, the activation of the menu works, i: I get the "Paused" message in the console, but iI can't get to unpause the menu, the. The bool remains true and additionally upon pressing again, the "Paused" message does not appear.

I tried to comment out the enabling and disabling of the ActionMaps, and this works partially since now the "Paused" message appears every time the key is pressed, but iI still cannot set the bool to false. I have also tried to use a single ActionMap but it doesn't work either.

Does someone have any suggestionsHow can I correct this? All help is appreciated!

Unity UI: Menu not disappearing after input

I am having some issues with the UI and the Input system. What I am trying to do is "simply" to make a menu appear and disappear upon pressing a certain key. To do so, i created an animator attached to the Menu canvas, to which I attached the following script:

The idea is that when i press the pause key (mapped in the actionMap of the player i.e. in game), the menu will be activated, the animation triggered in order to pass to the state transition 'menu activated', the in game ActionMap is disabled and the menu ActionMap enabled. Viceversa if the menu is already active (anim.GetBool("isPaused") == true), i will go the other way around.

So far, the activation of the menu works, i get the "Paused" message in the console, but i can't get to unpause the menu, the bool remains true and additionally upon pressing again, the "Paused" message does not appear.

I tried to comment out the enabling and disabling of the ActionMaps, this works partially since now the "Paused" message appears every time the key is pressed, but i still cannot set the bool to false. I have also tried to use a single ActionMap but it doesn't work either.

Does someone have any suggestions? All help is appreciated!

Menu not disappearing after input

I am having some issues with the UI and the Input system. What I am trying to do is "simply" to make a menu appear and disappear upon pressing a certain key. To do so, I created an animator attached to the Menu canvas, to which I attached the following script:

The idea is that when I press the pause key (mapped in the ActionMap of the player i.e. in-game), the menu will be activated, the animation triggered in order to pass to the state transition 'menu activated', the in game ActionMap is disabled and the menu ActionMap enabled.

Vice versa, if the menu is already active, (anim.GetBool("isPaused") == true), I will go the other way around.

So far, the activation of the menu works: I get the "Paused" message in the console, but I can't get to unpause the menu. The bool remains true and additionally upon pressing again, the "Paused" message does not appear.

I tried to comment out the enabling and disabling of the ActionMaps, and this works partially since now the "Paused" message appears every time the key is pressed, but I still cannot set the bool to false. I have also tried to use a single ActionMap but it doesn't work either.

How can I correct this?

Source Link
FSic
  • 188
  • 13

Unity UI: Menu not disappearing after input

I am having some issues with the UI and the Input system. What I am trying to do is "simply" to make a menu appear and disappear upon pressing a certain key. To do so, i created an animator attached to the Menu canvas, to which I attached the following script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Menu : MonoBehaviour
{
    [SerializeField] Animator anim;

    [Header("Input System")]
    [SerializeField] public GameController controls;
    //[SerializeField] public Vector2 direction;


    private void Awake()
    {
        anim = GetComponent<Animator>();

        controls = new GameController();
    }

    private void OnEnable()
    {
        controls.Enable();

        if (anim.GetBool("isPaused") == false)
        {
            controls.Player.ShowMenu_Start.performed += ctx =>
            {
                anim.SetBool("isPaused", true);
                Debug.Log("Paused");
                //controls.Player.Disable();
                //controls.Menu.Enable();
            };
        }
        
        if (anim.GetBool("isPaused") == true)
        {
            controls.Menu.HideMenu_Start.performed += ctx =>
            {
                anim.SetBool("isPaused", false);
                Debug.Log("Resumed");
                //controls.Menu.Disable();
                //controls.Player.Enable();
            };
        }    
    }
    private void OnDisable()
    {
        controls.Disable();
    }



}

The idea is that when i press the pause key (mapped in the actionMap of the player i.e. in game), the menu will be activated, the animation triggered in order to pass to the state transition 'menu activated', the in game ActionMap is disabled and the menu ActionMap enabled. Viceversa if the menu is already active (anim.GetBool("isPaused") == true), i will go the other way around.

So far, the activation of the menu works, i get the "Paused" message in the console, but i can't get to unpause the menu, the bool remains true and additionally upon pressing again, the "Paused" message does not appear.

I tried to comment out the enabling and disabling of the ActionMaps, this works partially since now the "Paused" message appears every time the key is pressed, but i still cannot set the bool to false. I have also tried to use a single ActionMap but it doesn't work either.

Does someone have any suggestions? All help is appreciated!