- Home /
Disable mouse click navigation when selecting GUI menu option
Hi, my problem is the following: I have a game where the player moves in a Diablo-like fashion, i.e. according to the player click on the map. The problem is that the player sometimes gets to talk to NPCs and, when clicking one of the possible answers, the menu button gets clicked but also the player starts running towards the point the map where the mouse button has been clicked. Now, I still want the player to be able to walk around with the mouse when a Dialogue menu pops up, but not when he clicks on a Dialogue option. I hope you understand what I mean, and that somebody of you knows an easy trick for this. Thanks in advance.
Answer by Ashish Dwivedi · Feb 04, 2014 at 03:44 AM
Use "GUIUtility.hotControl" as condition to check whether mouse is over GUI or not. GUIUtility.hotControl returns 0 if mouse is not over GUI and returns respective ID if mouse is over some GUI element.
void Update()
{
if(Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0)
{
//Code
}
if(Input.GetMouseButton(0) && GUIUtility.hotControl == 0)
{
//Code
}
if(Input.GetMouseButtonUp(0) && GUIUtility.hotControl == 0)
{
//Code
}
}
I think this would help you...
Your answer

Follow this Question
Related Questions
Trying to pick up and see paper - pop up GUI window to examine objects when clicked 3 Answers
Don't register Mouse Clicks through GUI. 1 Answer
Buttons that remove themselves when clicked mess up other gui elements 2 Answers
How to create a Event??? 1 Answer
how to call a gameobject in one function(mouse selection) to another function (GUI) 1 Answer