I’m attempting have the player take an action (fire a weapon, choose a waypoint) if any part of the screen is clicked, except if they have clicked the part of a screen that is a button. I can’t seem to limit the action click to the non-button parts of the screen.
Here’s an example:
if (GUI.Button (Rect(Screen.width*0.02,Screen.height*.02,Screen.width*0.1,Screen.height*0.1), "Move"))
{
waypointSet = "no";
viewMode = "overhead";
fireMode = "off";
}
if(Input.GetKeyDown(KeyCode.Mouse0) && viewMode == "ground" && fireMode == "on"){
Fire();
Debug.Log("Fire");
}
I’ve also tried:
if (GUI.Button (Rect (Screen.width*0.02,Screen.height*.02,Screen.width*0.1,Screen.height*0.1), "Move"))
{
waypointSet = "no";
viewMode = "overhead";
}
else if(Input.GetKeyDown(KeyCode.Mouse0) && viewMode == "ground"){
Fire();
Debug.Log("Fire");
}
You could try checking GUIUtility.hotControl
This will be populated with the GUI element that the mouse is over, so if it’s empty, you’re not over any GUI elements.
if (GUI.Button(Rect(Screen.width*0.02,Screen.height*.02,Screen.width*0.1,Screen.height*0.1), "Move"))
{
waypointSet = "no";
viewMode = "overhead";
fireMode = "off";
}
if(Input.GetKeyDown(KeyCode.Mouse0) && GUIUtility.hotControl == 0 && viewMode == "ground" && fireMode == "on"){
Fire();
Debug.Log("Fire");
}