- Home /
Intro GUI Text Script...
In the game I am working on, When the first level starts, I want to make a few GUI texts appear, one after the other. I don't know if I should script each text inside a script, or should I make premade gui texts and have them appear and disappear..?
Answer by Tetrad · Jan 02, 2011 at 01:25 AM
It really doesn't matter. Whatever's easier for you.
Like I said, whichever's easiest for you. I'm assu$$anonymous$$g you can set all the fields of a procedurally created gui text in code and that would include the font settings.
Answer by Lungfish · Jan 02, 2011 at 03:46 PM
But the problem is I don't actually know how to do either one...
Answer by Owen-Reynolds · Mar 11, 2011 at 06:20 PM
For multiple lines, it seems easiest to make one GUIText, and then child the other lines to it. The scale is (0,1)(0,1), so (0.5,0.5) is in the center. You won't see them until Play. Maybe best to Play, tweak them where they look good, then change the settings "for real" after Stop.
This is some mostly tested demo code in C# to change the message (lineTwo is childed to the GUIText with the script. The script is on the parent GUIText):
void Start () { StartCoroutine(showStuff()); }
// A predone set of messages over time IEnumerator showStuff() { transform.guiText.text="Firing..."; yield return new WaitForSeconds(2); transform.guiText.text="Missile is fired"; // put some text in second line: transform.Find("lineTwo").guiText.text="Woe to them"; yield return new WaitForSeconds(2); transform.guiText.text=""; transform.Find("lineTwo").guiText.text=""; }
// someone else can call this for any 1-time message: public IEnumerator flashMessage(string msg, float len) { transform.guiText.text=msg; yield return new WaitForSeconds(len); transform.Find("lineTwo").guiText.text="l"; }
Your answer
Follow this Question
Related Questions
GUIText Help 1 Answer
Level Button And Quit Button Android 2 Answers
How to save and load text in a GUI TextArea 1 Answer
How do I Script GUI Text Objects? 1 Answer
Scrolling Text 1 Answer