반응형
- 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RankingSystem : MonoBehaviour
{
private List<int> playerScores;
private void Start()
{
playerScores = new List<int>();
AddScore(500);
AddScore(1000);
AddScore(750);
AddScore(300);
SortScores();
PrintRanking();
}
public void AddScore(int score)
{
playerScores.Add(score);
}
public void SortScores() //오름차순 정리
{
playerScores.Sort((a, b) => b.CompareTo(a));
}
public void PrintRanking() 랭킹 표시
{
Debug.Log("Current Ranking:");
for (int i = 0; i < playerScores.Count; i++)
{
Debug.Log("Rank " + (i + 1) + ": Score - " + playerScores[i]);
}
}
}
반응형