How Do I Display Multiple Strings In Here?

This script pretty much makes a Debug/Chat log but it only displays one string at a time.
How do i get it to print the next string underneath rather than overwrite the previous one?

var stringToEdit : String = "";


function OnGUI() {
GUI.Label(Rect(10, Screen.height / 4*3.5, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
	}

Increment the Y value after you write each string

var stringToEdit : String = "";
 int y = Screen.height / 4*3.5;
 
 function OnGUI() 
     {
        GUI.Label(Rect(10, y, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
		y += Screen.height / 4*3.5;
     }

I’m a bit new to this, so I’m guessing that’s where the y value is passed in for the label.

var offsetY:float = 50f;
function OnGUI() {
for(var i:int = 0; i < amountOfString; i++){
GUI.Label(Rect(10, (Screen.height / 4*3.5) + offsetY * i, Screen.width / 3, Screen.height / 10), stringToEdit, “textarea”);
}
}

offsetY is how much space you want between each writing. Then the y value of the printing gets the original place plus this offset times the i value.

So the first will get

 (Screen.height / 4*3.5) + offsetY * i -> i is 0
 (Screen.height / 4*3.5) + offsetY * i -> i is 1 so 50 
 (Screen.height / 4*3.5) + offsetY * i -> i is 2 so 100

and so on

As an alternate to placing multiple labels (which will work), you can take your collection of strings and build a single string that has a newline between each string.

#pragma strict
            
private var stringToEdit : String = "";
private var chatLines : String[] = ["One", "Two", "Three", "Four", "Five", "Six"];

function Start() {
	BuildText();
}
 
 function OnGUI() {
 	GUI.Label(Rect(10, Screen.height / 4*3.5, Screen.width / 3, Screen.height / 10), stringToEdit, "textarea");
 }

function BuildText() {
	stringToEdit = "";
	for (var i = 0; i < chatLines.Length; i++) {
		stringToEdit += chatLines *+ "

";*

  • }*
    }
    In this bit of sample code, chatLines would be the incoming chat lines. You would be updating this list each time a new line comes in and then calling BuildText. Attach this sample code to an empty game object and hit run.