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 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
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.