GUILayout Sort Problem

Hello Everyone
I Was Doing a C# Game Chat [All - Team - Whisper]
and its work fine.
but there is problem with the Sorting

Lemme Show You The Picture i Will Explain More
[8325-achat+problem.png|8325]

Here We Go :

The [All] Chat Togather
And The Team Chat Togather
and Whisper Chat Togather

its not sorted by Newest!

Its Shows This Way
2 To All , 5 To All , 3 To Team , 4 To Team

It Should Be : 2 To All , 3 To Team , 4 To Team , 5 To All

i hope You Got It

And Here is the Code i Use

	myStyle.normal.textColor = Color.magenta;
	GUILayout.Label(communicationWhisper,myStyle);
	
	myStyle.normal.textColor = Color.cyan;
	GUILayout.Label(communicationTeam,myStyle);
		
	myStyle.normal.textColor = Color.white;
	GUILayout.Label(communication,myStyle);

I am just going to give this a shot as I do not fully understand your explanation.

From your code fragment, you are just outputting the 3 sets of communication separately. From what I can see, I think that in your current script, you just append the latest message to a string variable or gui content ( communicationWhisper, communicationTeam, communication ). By doing so, you can only sort them by separately, not as a whole chat.

What you need to do is to create a new class to store the message.

public enum CommType{ NORMAL, WHISPER, TEAM };

public class Message {
   public string content;
   public CommType commType;

   public Message( string cont, CommType ct ) {
       //Standard constructor
   }
}

Then, in your chat script

List <Message> chat = new List<Message>();

All message will go to this chat variable. Whenever there is a new piece coming in:

chat.Add( new Message("My Message", CommType.WHISPER ) );

On output, do this:

//We are iterating the list in reverse order, as the newest message starts from the back
for(int i = chat.Count - 1; i >= 0; --i ) {       
   //Use either a function or a if-else structure to determine the textColor, 
   //I am using a function in this example
   myStyle.normal.textColor = CommColor( chat*.commType );*

GUILayout.Label( chat*.content, myStyle );*
}
Hope that this is what you are looking for.
----------
## Code Test ##
This is what I got after implementing the codes. By the way, I wrote a test class that send messages to the chatControl object by detecting different Input.GetKeyDown(KeyCode.??)
I hope that this code is what you are looking for.
[8462-screenshot.2.png|8462]_
_
[8463-screenshot.4.png*|8463]*
_*
_*