How do I stop my main menu from closing before the player is done interacting with it?
My main menu opens/closes whenever a player presses "enter". Sometimes, when it's open, it shouldn't be able to close, like for example, when a player is holding an item with the computer mouse. I don't want the menu to close and leave the item still held, this introduces a lot of bugs and also looks very strange.
My script for opening the main menu is: private void Update() { if (Input.GetButtonDown("Submit") && canOpenMainMenu) { if (GetComponentInChildren<ItemHover>()) return; //The menu is now up/not up depending on what state it was previously in mainMenuUp = !mainMenuUp; //The menu is now changing, the player's freedom is altered FindObjectOfType<PlayerScanner>().canScan = !mainMenuUp; FindObjectOfType<PlayerMovement>().canMove = !mainMenuUp; //Submenu is told where to go mainMenuAnim.SetBool("IsUp", mainMenuUp);
Whenever an item is picked up from the menu inventory screen by the player, if they press the "Submit" button fast enough (enter) they can close the menu while the inventory item is still held. I tried to stop this by updating the script which is called when an inventory slot is pressed: //Called when an item slot is clicked, checks to see if there's an item, and holds it/swaps it/puts on there public void EditSlot(InventorySlot theSlot) { if(theSlot.itemInSlot != null) { menuController.canChangeSubmenu = false; menuController.canOpenMainMenu = false; Debug.Log("Menu can no longer be opened or closed"); }
This still doesn't fix the small timeframe that the player has to open/close the menu while still holding an item. Is there any method to prevent this?
Your answer
Follow this Question
Related Questions
How to remove flashing screen when changing Canvas Render Modes 0 Answers
Animation Resets Position When Played: 0 Answers
How to show and hide a Button and don't affect the Animation on it. 0 Answers
Inspector field overlap bug 0 Answers
Animation transition locks up temporarily during runtime of exe, works fine in editor 0 Answers