I have made the script below, which prints out just fine to the console, but what do I do to print the list on the screen when pressing a button? Code (csharp): using UnityEngine; using System.Collections; using System.Collections.Generic; public class CreateGoal : MonoBehaviour { public List<string> stringList = new List<string>(); public string stringToEdit = "Define your goal here"; void OnGUI() { stringToEdit = GUI.TextField(new Rect(10, 50, 210, 21), stringToEdit, 100); if (GUI.Button(new Rect(10, 80, 210, 21), "Add")){ stringList.Add(stringToEdit); } if (GUI.Button(new Rect(100, 110, 210, 21), "Debug List to console")){ DebugList(); } } void DebugList(){ foreach(string s in stringList){ Debug.Log(s); } } }
Iterate through the strings in the list and create Labels for each one, changing the coordinates appropriately.
I have now tried to do, what you suggested, but there are something that does´nt work. What am I missing? Code (csharp): using UnityEngine; using System.Collections; using System.Collections.Generic; public class CreateGoal : MonoBehaviour { int PrintLabelPosition = 200; public List<string> stringList = new List<string>(); public string stringToEdit = "Define your goal here"; void OnGUI() { stringToEdit = GUI.TextField(new Rect(10, 50, 210, 21), stringToEdit, 100); if (GUI.Button(new Rect(10, 80, 210, 21), "Add")){ stringList.Add(stringToEdit); } if (GUI.Button(new Rect(100, 110, 210, 21), "Debug List to console")){ DebugList(); } //Button for printing out the strings in the list if (GUI.Button(new Rect(100, 140, 210, 21), "Print list to screen")){ PrintList(); } } void DebugList(){ foreach(string s in stringList){ Debug.Log(s); } //Function that prints out the strings in the list void PrintList(){ foreach(string s in stringList){ GUI.Label(new Rect(10, PrintLabelPosition, 200, 20), s); PrintLabelPosition = PrintLabelPosition + 30; } } }