- Home /
Fill a Control with text from the bottom to the top...to mimic a chat window
I want to create a stack based fill to mimick a normal chat window.
What GUI contructs do I need to use.
Thanks, stringa
This must either be a stupid question or a really hard question... I can't believe that this is difficult...
Answer by jrfactotum · Oct 21, 2010 at 05:59 AM
A simple method would be to add the new messages to the end of the current content, then redisplay it in a GUI box (example in C#):
void OnGUI() { string chatContent = "This is a chat window\nwith\nmultiple\nlines"; string newChatContent = "\nand\neven\nmore\nlines";
if (newChatContent.Length > 0)
chatContent += newChatContent;
GUIStyle style = new GUIStyle();
GUIStyleState styleState = new GUIStyleState();
styleState.textColor = Color.cyan;
style.alignment = TextAnchor.LowerLeft;
style.normal = styleState;
GUI.Box(new Rect(0, 0, 400, 200), chatContent, style);
}
Instead of a string for the content you could use a List of strings, which would provide easy addition and removal of lines.
As for a way to enter messages, look into GUI.TextField. See also the GUI Scripting Guide:
http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html
This is an interesting post about how to make a chat system:
http://forum.unity3d.com/threads/50369-Hep!-Display-what-you-have-entered-in-chat-window
Your answer
![](https://koobas.hobune.stream/wayback/20220613080259im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can you have a scrollview inside a textfield? 0 Answers
speech / chat bubbles above character or game object 0 Answers
BeginScrollView question on auto increasing 1 Answer
How can I release gui focus via code? 6 Answers
GUILayout Sort Problem 1 Answer