Im trying to create a leaderboard for my game. I am looping through a list of leaders and want to align names on the left and scores on the right.
I plan on limiting names to only 5 letters – so my code of 3 tabs would work ( see the image - toddv and 24 look fine ) but this just seems terribly hacky and brutal and would probably break on different screen sizes.
I’m willing to go a whole different route, but just would love some suggestions. (hackish code below)
foreach (Score score in highScoresList)
{
theBoard.text += score.playerName + "\\t\\t\\t" + score.score + "\\n ";
}
theBoard.text = theBoard.text.Replace("\\n", "\n");
theBoard.text = theBoard.text.Replace("\\t", "\t");
Are you using the new Unity GUI? If so, you can take advantage of the alignment properties on the Text component. Create a column for the names and another for the scores. Align each to your needs and that’s pretty much it.
1 Like
Ah ha… I’m assuming you are suggesting that I use extra text boxes as columns (and it looks like it will work) - I’m going to use two extra text boxes under CONTENT in the scroll rect… that should work!
Fantastic! Thanks Trav3l3r!!! ( So do you know how to force it to scroll to the top from code? )
var scrollView = GameObject.FindGameObjectsWithTag("ScrollView");
foreach (var scrollRect in scrollView)
{
scrollRect.GetComponent<ScrollRect>().velocity = new Vector2(0f, -3000f);
}
Glad I was able to help
I believe you can simply translate the Content object to the desired location
something along the lines of (from the top of my head)
void FixedUpdate(){
//content is a public var pointing to your Content object
//target is a public var pointing to a target destination objec. Or it could also be a Vector3
content.position = Vector3.MoveTowards(content.position, target.position, speed * Time.deltaTime);
}
1 Like