How to sort list in Leaderboard with animation
Hello, I created a leaderboard where i can enter new teams and scores it can sort the list it is fine. When i deactivate the sorting part then it adds as normal of course but I want to do is this way.
--> My system is working like that for now (video - https://streamable.com/0n1ozc)
lets say at first when the panel opened to player it will show 11 other teams(which are already sorted by their scores.)
and when i passed the level it will first add me on the last row of leaderboar then lets say i can be the third one this level so from the last row it will move to up with an animation. JUST LIKE THIS = https://youtu.be/fezO1wmb9v8?t=165 (head ball 2 game leaderboard) my system wont be online i mean other enemies scores will be based on a calculation.
--> ScoreUI Class < --- private void SortList() { var scores = scoreManager.GetHighScores().ToArray(); //when i click the button to add new team info it adds under the previous ones so i remove the previous ones first here if (transform.childCount > 0) { for (int j = 0; j < transform.childCount; j++) Destroy(transform.GetChild(j).gameObject); } for (int i = 0; i < scores.Length; i++) { var row = Instantiate(rowUi, transform).GetComponent (); if (i == scores.Length - 1) row.transform.localScale = Vector3.zero; row.rank.text = (i + 1).ToString(); row.name.text = scores[i].name; row.score.text = scores[i].score.ToString(); if (i == scores.Length - 1) { RectTransform rowRectTransform = row.GetComponent (); rowRectTransform.DOScale(Vector3.one, .4f).SetEase(Ease.InOutBounce); } } }
public void AddTeamInList() { int.TryParse(inputTeamScore.text, out score); scoreManager.AddScore(new Score(inputTeamName.text, score)); var scores = scoreManager.GetHighScores().ToArray(); SortList(); print(scores.Length); } -->> ScoreManager Class << -- public IEnumerable GetHighScores() { return sd.scores.OrderByDescending(x => x.score); } public void AddScore(Score score) { sd.scores.Add(score); } -->> RowUI Class << -- public class RowUI : MonoBehaviour { public Text rank; public Text name; public Text score; } -->> Score Class << -- public string name; public int score;
public Score(string name, int score) { this.name = name; this.score = score; } -->> ScoreData Class << -- public List scores;
public ScoreData() { scores = new List(); }
Your answer
![](https://koobas.hobune.stream/wayback/20220613041614im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Array.Sort() - JS only???! 0 Answers
How to play animations from script. 0 Answers
How to play all the animations array inside animation component 0 Answers
Animation Transition Unity 0 Answers
Getting objects out of a list and then comparing them 0 Answers