How to use NewInput System in order to performe the action open and close with same key(ESC). Both CallBacks are called at the same time and the menu does not open.
void Start () {
gameKeyController.Menu.Back.performed += _ => GoBack();
gameKeyController.Default.OpenMenu.performed += _ => OpenMenu();
}
public void GoBack()
{
if (!GameManager.Instance.getAnimationMenu().isBlocking())//WILL BE ESCAPE
{
if (isMenuOpen == true)
{
isMenuOpen = false;
if (menuInGame.activeSelf == true)
{
Debug.Log("Back");
menuInGame.SetActive(false);
}
//escapeFunctionality();
}
}
}
public void OpenMenu()
{
if (!GameManager.Instance.getAnimationMenu().isBlocking())//WILL BE ESCAPE
{
if (isMenuOpen == false)
{
isMenuOpen = true;
Debug.Log("OpenMenu");
menuInGame.SetActive(true);
}
}
}
I found a trick. I hope there is a cleaner way to implement it, pls porvide it and i will replace the Solution.
current solution: I add some delay to the method that would change the open state(isMenuOpen), this way the one that would set the state(isMenuOpen) to the same values runs before the one that will change it.
void Start () {
gameKeyController.Menu.Back.performed += _ => GoBack();
gameKeyController.Default.OpenMenu.performed += _ => OpenMenu();
}
private bool isMenuOpen = true;
public void GoBack()
{
StartCoroutine(C_GoBack());
}
public IEnumerator C_GoBack()
{
if (isMenuOpen == true)
{
yield return new WaitForSeconds(0.1f);
}
if (!GameManager.Instance.getAnimationMenu().isBlocking())//WILL BE ESCAPE
{
if (isMenuOpen == true)
{
isMenuOpen = false;
Debug.Log("Back");
if (menuInGame.activeSelf == true)
{
menuInGame.SetActive(false);
}
//escapeFunctionality();
}
}
}
public IEnumerator C_OpenMenu()
{
if (isMenuOpen == false)
{
yield return new WaitForSeconds(0.1f);
}
if (!GameManager.Instance.getAnimationMenu().isBlocking())//WILL BE ESCAPE
{
if (isMenuOpen == false)
{
isMenuOpen = true;
Debug.Log("OpenMenu");
menuInGame.SetActive(true);
}
}
}