- Home /
GUITexture and GameObject OnMouseDown() Problem
Greetings. I am having difficulty trying to figure out how to click on a GUITexture onscreen without activating a GameObject's OnMouseDown() if that GameObject is covered by the GUITexture. The idea is that I click on the GameObject, which brings up a menu above it (The GUITexture(s)) that I can interact with; however, clicking on the GUITexture(s) seems to activate the OnMouseDown() of the GameObject, which intentionally causes the menu to disappear (I only want the menu to disappear when the part of the object that is showing is clicked; otherwise, I'd like anything covered by the menu to not be activated). What is the best way to fix this problem?
Answer by Dexter.Unity · Dec 05, 2012 at 10:29 PM
I think you should place the GUI script parts on you camera.
Then on click of the game object make a boolean true, which will make you see the GUI.
Your GUI will be part of the Camera on which you can't click.
Ohh wait the GUI text has to be INSIDE the 3d environment?
In that case you shouldn't make the GUI text a child of the GameObject but just stand next to it (in the Hierarchy)
The menu is not parented to anything in the hierarchy. It is a separate GUIElement that, in the viewport, is "covers" other GameObjects with On$$anonymous$$ouseDown() functions. I want to be able to click on the menu without activating the separate, unrelated GameObject beneath it's On$$anonymous$$ouseDown() function.
I don't know exactly how to prevent the On$$anonymous$$ouseDown of the other objects. But you can add a boolean in the script that triggers the menu hide. This boolean is false when the menu is opend and true when it's closed. This way the script will know the menu's status and won't execute the close menu when the menu is opend
Or do you want other objects to close the menu when it's not hovering? x)
$$anonymous$$y intent is to click on other GameObjects nearby the one that I clicked on to reposition the menu and populate it with information pertaining to those GameObjects. Basically, I click on a GameObject, it sends a message to the menu script (Which is attached to the camera) telling it to open, and I should be able to interact with it, without calling the On$$anonymous$$ouseDown() of the things it is covering. If I click on the uncovered portion of the GameObject that originally told the menu to open, then the menu should close. If I click on any other GameObject while it is open, again, the menu should move to its viewport position and display the relevant information. The GameObjects are all tightly packed in the world space.