- Home /
How do I make my textlabel stay after the user clicks on a structure?
I am trying to add a textlabel or label with some text that pops up after the user clicks down on an object. For example, if I have an mesh of an apple on the screen and the user clicks on the apple, a label would appear that says, "apple". However, currently in my script, as soon as the user lets go of the mouse click, the label disappears. I want the label to remain until the user navigates to another mesh and clicks it or goes back to click on the same structure again and have it disappear.
Currently what I have is:
var _mouseDown = false;
function OnGUI() {
if(_mouseDown) {
GUI.Box(Rect(10,10,100,20),"left femur!");
}
}
function OnMouseDown () {
_mouseDown = true;
}
function OnMouseUp () {
_mouseDown = false;
}
function OnMouseOut() {
_mouseDown = false;
}
Answer by b45h05h4 · Dec 10, 2013 at 07:25 PM
from the menus
GameObject >> Create Other >> 3D Text
in the scene place this text where you wish it to appear then
in your code
public TextMesh text; //drag the 3D text on this variable in the inspector
//in the place where you want to control the time of appearance like(onMouseDown) write this
text.text = "Apple";
text.renderer.enabled = true; // and false to make it disappear of course
How do I make the text disappear if I click on a separate object?
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Network Error 0 Answers
Unity model scripting question 1 Answer