Why is this List only showing one int?
public GUISkin guiSkin;
public Font yourFont;
public int guiDepth;
private static int lengthOfLeaderboard;
GUIStyle customButtonStyle;
public Text leaderboard;
string date= "";
string score="";
string time="";
List<Scores> highscore;
void Start () {
highscore = new List<Scores>();
lengthOfLeaderboard = HighScoreManager.LeaderBoardLength;
}
void Update ()
{
leaderboard = leaderboard.GetComponent<Text>();
highscore = HighScoreManager._instance.GetHighScore();
foreach (Scores _score in highscore)
{
leaderboard.text = "" + _score.score;
}
}
I can't get this code to list more than one int. It only lists the last high score out of 5 high scores. Can anyone tell me what I'm doing wrong?
The old GUILayout code I had listed all 5 high scores fine, but this way of doing it using Unity UI's Text isn't working as well. It's been a very difficult process transitioning from GUILayout to Unity 5 UI.
Any help is appreciated.
As it is, it looks like you are overwriting the content of your text component every time you go through the loop, which is why you are only seeing the last high score. You would either have to use a separate text component for each high score, or you could use your one text component and add to the text every time through the loop ins$$anonymous$$d of overwriting it.
void Update ()
{
leaderboard = leaderboard.GetComponent<Text>();
highscore = HighScore$$anonymous$$anager._instance.GetHighScore();
leaderboard.text = "";
foreach (Scores _score in highscore)
{
leaderboard.text += _score.score + System.Environment.NewLine;
}
}
Your text component would have to be large enough to fit all that text in it. Having this text update every update cycle probably isn't great for performance.
You're amazing. I've never heard of "System.Environment.NewLine". In the three hours of searching for an answer that never came up.
Thanks for the help, it worked like a charm!
Edit: just noticed your last sentence about the update function. I've moved it to the Start function, as it only needs to load once when the player enters the scene. Thanks for that heads up as well (I have a tendency to use the Update function unnecessarily...).