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!