I'll start by saying that I'm working on Unity, I need to manage the menu input in the Oculus controller but every time I press the button it only works that time and that's it. If I set breakpoints it works every time
public void Update()
{
if (menu.activeSelf == true && smenu.activeSelf == true)
{
menu.SetActive(false);
smenu.SetActive(false);
}
if (menu.activeSelf == true && amenu.activeSelf == true)
{
menu.SetActive(false);
amenu.SetActive(false);
}
if (menu.activeSelf == true && imenu.activeSelf == true)
{
menu.SetActive(false);
imenu.SetActive(false);
}
if (Input.GetKeyDown(KeyCode.Menu) || Input.GetKeyDown(KeyCode.T))
{
ToggleMenu();
Debug.Log("Pause menu ON");
}
if(Input.GetKeyDown(KeyCode.JoystickButton3) || Input.GetKeyDown(KeyCode.JoystickButton1))
{
ToggleMenu();
Debug.Log("Pause menu ON");
}
}
public void ToggleMenu()
{
if (menu != null)
{
// Inverti lo stato attivo/inattivo del menu
menu.SetActive(!menu.activeSelf);
Debug.Log("TOGGLE MENU");
}
}
Update function will be called each frame so when user press the button, ToggleMenu function will be called continuous until user released the button. Breakpoint will prevent ToggleMenu call several times. You can check reference my code to fix it:
if ((Input.GetKeyDown(KeyCode.Menu) || Input.GetKeyDown(KeyCode.T)) && !menuPressed)
{
ToggleMenu();
Debug.Log("Pause menu ON");
menuPressed = true; // Mark as pressed
}
else if (menuTogglePressed && (Input.GetKeyUp(KeyCode.Menu) || Input.GetKeyUp(KeyCode.T)))
{
menuPressed = false; // Reset the flag when the key is released
}