- Home /
How to implement an interactive text
I'm looking for a way to make interactive some words of a text. Something like links of a webpage.
I tried to split my text in different part, interactive words and the rest, and I displayed non interactive text in GUI Labels and interactive words in GUI Buttons but I don't find a way to arrange them to have something that looks like a basic text (the problem is to set a "new line")
Am i in a wrong way ?
Answer by KevS · Jul 19, 2011 at 10:14 AM
I find a better solution !!!! :D
Here is THE function : GUIStyle.GetCursorStringIndex
With these function (and a bit of code ^^), i will be able to know on wich word my mouse is over, and trigger events if needed :D
First test :
public GUISkin skin;
public Rect textArea;
public int cursorIndex;
public string myText;
void Start ()
{
textArea = new Rect (0, 0, 500, 30);
myText = "My entire text to display.";
}
void OnGUI ()
{
GUI.skin = skin;
GUI.Label (textArea, myText);
cursorIndex = GUI.skin.GetStyle ("MyLabel").GetCursorStringIndex (textArea, new GUIContent (myText), Event.current.mousePosition);
}
Your answer
Follow this Question
Related Questions
How to make font bold on mouse over (c#) 2 Answers
Interactive Story Based game algorithm 1 Answer
Accessing button text 2 Answers
Help Changing GUI Text size 0 Answers