- Home /
Question by
SteenPetersen · Aug 13, 2017 at 12:52 PM ·
guilayoutlabelgui.label
Gui.Label chat system direction of label "stacking"
Hi there I am making a chat system for my game. I have all the networking working like I want it but I am now messing with the actual layout.
As messages come in I want the second message to appear above the first message in the picture above. Secondly I would want each individual label to fade out but still be there after a certain amount of time.
here is the script so far:
public class Chat : MonoBehaviour {
public List<string> chatHistory = new List<string>();
Client client;
public string thisPlayer;
public GUISkin skin;
private string currentMessage = string.Empty;
Rect textEntry = new Rect(0, Screen.height - 25, 175, 20);
private void OnGUI()
{
if (!Client.isConnected)
return;
LoadGui();
}
private void LoadGui()
{
currentMessage = GUI.TextField(textEntry, currentMessage);
if (GUI.Button(new Rect(200, Screen.height - 25, 75, 20), "Send"))
{
SendMessage();
}
GUILayout.Space(Screen.height - 45);
foreach (string c in chatHistory)
{
GUI.skin = skin;
GUILayout.Label(c);
}
}
// send message function
public void ReceiveMessage(string message, string playerName)
{
string timeOfMsg = "[" + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second + "]";
chatHistory.Add(timeOfMsg + " " + playerName + ": " + message);
}
}
Any feedback would be greatly appreciated.
chat-example.png
(21.7 kB)
Comment