- Home /
OnMouseDown creating text boxes
Hi all,
I am new to unity and trying to create an informative architectural walkthrough. One where, the FPC walks through a level and can select (OnMouseDown) various pieces of architecture and learn more about them. (have a text box appear)
I am having trouble making this happen.
I have a bit of code
private var showBox = false;
function OnMouseOver () {
if (Input.GetMouseButtonDown) showBox = true;
}
function OnGUI () {
if (showBox) GUILayout.Box("A classic neovictorian turret");
}
, attached to a turret with a collider and I want a textbox to appear when the user clicks it, however currently the text appear on MouseOVer and then does not dissapear once the mouse exits.
I am sure it is probably an issue with my bool but I am having trouble making the GUI stuff work.
Thanks K
Answer by Waz · Jul 13, 2011 at 12:56 PM
You also need an OnMouseExit function that sets showBox to false.
Thanks a lot!
It now works when I hover over the object and disappears when I exit, However, I the functionality where it only appears once clicked (On$$anonymous$$ouseDown) is not working. Thoughts?
Thanks again
Simplest way to thank is to just click the checkmark. Also, for the benefit of others, you could comment how you got it to work. Not really necessary for this question, but worth remembering in the future.
Your answer
Follow this Question
Related Questions
How do I make onMouseDown work for OnGUI in C#? 1 Answer
How to make a GUI button appear OnMouseDown 1 Answer
GUI.Box doesn't show when GUI.Button is clicked 2 Answers
Help with GUI class 1 Answer
highlight object color 3 Answers