- Home /
Make text appear when object is clicked
i have an object...lets call it "cube" i want text to appear saying "door is locked" when "cube" is clicked i know it has to be OnMouseDown () but i dont know exactly how i want the text to come in the form of a GUI button
Comment
Best Answer
Answer by tw1st3d · Aug 20, 2013 at 02:56 AM
using UnityEngine;
using System.Collections;
class ShowTextButton : MonoBehavior
{
private bool showText = false;
// Create a bool to say whether to show the button or not
void OnMouseDown()
{
if(!showText)
showText = true;
// If you clicked the object, set showText to true
}
void OnGUI()
{
if(showText)
{
// If you've clicked the object, show this button
if(GUI.Button(new Rect(100,100,100,20), "Click To Close"))
// If you click this button, set showText to false
showText = false;
}
}
}
Answer by RedMoonGms · Jun 07, 2017 at 06:45 AM
@tw1st3d It says there's an error that has to do with MonoBehaviour The rest seems to be OK Why?
Your answer
Follow this Question
Related Questions
Trigger collision with Player won't work 2 Answers
Big text field GUI. 1 Answer
Displaying varying text 1 Answer