- Home /
Simulating a Log
Hi, I'm trying to achieve a "Log" for in my game. It's supposed to be a window in my HUD that keeps track of a couple of variables. So I basically want to sent strings with some variables to it once every few minutes.
What kind of GUI element should I use and how could I sent strings to that element?
Answer by Justin Warner · May 25, 2012 at 05:43 PM
You can have multiple ones so that it's a "sliding" log, at most shows 3 messages.
http://unity3d.com/support/documentation/ScriptReference/GUIText.html
And then you can just update it by getting the users GUI... If you need more info on it, ask.
Answer by Mortoc · May 25, 2012 at 05:51 PM
I would use GUI (or GUILayout) Label for the log. If you have say 4 lines of text you can just use 4 Labels with static positions and change the strings in them when the log changes.
If you wanted the lines of the log to slide in an animation, put everything inside a GUI.Box that clips children and use 1 extra label that's clipped off the bottom. When you add a new line of text, start a coroutine that slides all the labels up one position and when the animation is done, reset the label positions with the new text in each label.
This is more complicated than using a GUI.ScrollView, but you don't want to have an unlimited number of labels since the engine still has to calculate their coordinates every frame and eventually you'll have way too many Labels being drawn that are unseen.
Your answer
Follow this Question
Related Questions
How Do I Display Multiple Strings In Here? 3 Answers
format text block in GUI.Box 1 Answer
changing GUI Button text with a string array 2 Answers