Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity3D中的简单记分牌,用于排名第一、第二和第三_C#_Visual Studio_Unity3d_Ranking - Fatal编程技术网

C# Unity3D中的简单记分牌,用于排名第一、第二和第三

C# Unity3D中的简单记分牌,用于排名第一、第二和第三,c#,visual-studio,unity3d,ranking,C#,Visual Studio,Unity3d,Ranking,我正在unity中制作一个简单的记分板,它通过按钮进行分数的加减,但我不知道如何将分数从第一、第二和第三位排序 就像大多数比赛一样,我只想展示前三名的最高得分。尽管这个例子只显示了两个分数,但这个程序可能需要对多达10个分数进行排名 有什么建议吗 public class Scores : MonoBehaviour { public Text scoreText; public Text scoreText2; public Text firstPlace; p

我正在unity中制作一个简单的记分板,它通过按钮进行分数的加减,但我不知道如何将分数从第一、第二和第三位排序

就像大多数比赛一样,我只想展示前三名的最高得分。尽管这个例子只显示了两个分数,但这个程序可能需要对多达10个分数进行排名

有什么建议吗

public class Scores : MonoBehaviour
{
    public Text scoreText;
    public Text scoreText2;
    public Text firstPlace;
    public Text secondPlace;
    public Text thirdPlace;
    public int score;
    public int score2;

    public void Addition()
    {
        score++;
        scoreText.text = "" + score;
    }

    public void Subtraction()
    {      
        score--;
        scoreText.text = "" + score;
    }

    private void Update()
    {
        if (score > score2)
        {
            firstPlace.text = "Texas A&M";
            secondPlace.text = "University of Houston";
            thirdPlace.text = "LSU"
        }
     }
}  

实现这一目标的更好方法是使用字典:

// Create a dictionary
public Dictionary <float,string> scores = new Dictionary<float ,string>();

// Add scores you want to add
scores.Add(1,"SomeText");
scores.Add(4,"SomeOtherText");
scores.Add(3,"SomeOtherText");

// convert the keys into a list
float[] order = scores.Keys.ToList();
// sort array in reverse order
order.Sort.Reverse();

/// print the order
Console.Log("First Place"+scores[order[0]]);
Console.Log("Second Place"+scores[order[1]]);
Console.Log("Third Place"+scores[order[2]]);
//创建字典
公共字典分数=新字典();
//添加您想要添加的分数
添加(1,“某些文本”);
添加(4,“其他文字”);
添加(3,“其他文字”);
//将键转换为列表
float[]顺序=scores.Keys.ToList();
//按相反顺序对数组排序
order.Sort.Reverse();
///打印订单
Console.Log(“第一名”+分数[顺序[0]]);
Console.Log(“第二名”+分数[顺序[1]]);
Console.Log(“第三名”+分数[顺序[2]]);

参考文献:



请原谅我的拼写错误。

好吧。。就像所有的事情一样,从你作为一个人类应该如何做开始。好的,我将进入上面的解决方案