Displaying list of ints

Ok in my previous question i found out how to use lists and after reading the documentation on them id like to find out how to display them in a label inside on unity
here is what i have so far if its not to much bother to read through :slight_smile:
id also like to know how to sort it

Creating the list
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class NextLevel : MonoBehaviour {
public int LevelName;
public bool ResetTime;
// Use this for initialization

	public List<int> iList = new List<int>();
	void OnTriggerEnter2D(Collider2D col) 
	{
	
		if (col.tag == "NextLevel")
		{
			Application.LoadLevel (LevelName); 

			if (ResetTime == true)
			{	
				iList.Add(PlayerPrefs.GetInt("Time"));
				PlayerPrefs.SetInt("Time", 0);
			}
		}
	}


}

And in a seperate script in the main menu id like it to display it

using UnityEngine;
using System.Collections;

public class HighScore : MonoBehaviour {


	
	
	NextLevel s1;
 
    IEnumerator Start()
    {
        s1 = GetComponent<NextLevel>();
        yield return new WaitForEndOfFrame();
        foreach(int i in s1.iList)
        print (i);
    }
}

but i cant find a good way to display it in a label

Please, be more specific. What are those labels for? Are they going to be on top of some game objects? Are they going to the interface? Will they be temporary?

–

in the main menu scene their will be 3 lables showing the top 3 times

–

but realy all i need to know atm is how to display a place in the list in a lable

–

While the new UI feature is still in Beta, you can use GUIText ([docs][1], [API][2]). If you are going for the new UI, you should check the tutorials [here][3]. [1]: http://docs.unity3d.com/Manual/class-GuiText.html [2]: http://docs.unity3d.com/ScriptReference/GUIText.html [3]: http://unity3d.com/es/learn/tutorials/modules/beginner/ui/ui-text

–

im not using 4.6 ui im using old gui

–

1 Answer

1

Using old GUI solution must be like so:

void OnGUI () {
    string array = string.Empty;
    foreach(int i in s1.iList)
        array += i.ToString();

    GUILayout.Label (array);
}

why convert it to an array?

–