- Home /
How to disable mouse click detection in game when clicking exit menu button?
So i made a script that instantiates a cube on Input.GetButtonUp("Fire1").
I also have a menu and anytime i click the button to close the menu the cube instantiates (obviously not my intention). I have no idea how to get around it. I tried checking that the menu is closed before instantiating, but it doesn't work. Also tried counting frames after the menu closes. Tried moving the close menu function after the instantiate function so the instantiate function would be called a frame after the close menu function. nothing.
Does anyone have any ideas? The script this is in handles a lot of other things, so the code is too long to post in here. But I could try if it would make a difference.
If it too long to post you should try to section it off into smaller scripts. Then you can have better control over your scripts.
Answer by Sxythe · Feb 19, 2020 at 02:19 PM
You could add an additional check (EventSystem.current.currentSelectedGameObject == null) to your Input.GetButtonUp("Fire1"). This way, you will only instantiate a cube when your mouse isn't hovering above a button.
Make sure to add using UnityEngine.EventSystems aswell.
Your answer
Follow this Question
Related Questions
Is there a built-in function to determine if any GUI item has been clicked? 2 Answers
Using Input.mouseposition to instantiate 1 Answer
Ensuring Correct Call Order 0 Answers
GUI text Main Menu 1 Answer