I am currently following a tutorial on making a game in Unity using C#. In it, they showed us how to show the score in the center of the screen using
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public Transform player;
public Text scoreText;
// Update is called once per frame
void Update()
{
scoreText.text = player.position.z.ToString("0");
}
}
However, I want to go further and figure out how to make a high score list in the top left corner. My only experience is with python so I know I would go about making an empty array of size 10, and then each time the game restarts, if the score is greater than any of the highest 10 scores in the mentioned list, it is inserted in the corresponding position (keeping the elements ordered), and the lowest value is dropped from the list (to keep a list of just 10 elements). However, I am confused about the syntax of C#.
Currently, my thought process for the code (which would go on my restart statement), if it were python is this
##this is how I would write it in python I believe
array = np.zeros[10]
for i in range(0, len(array)):
if player.position.z.ToString("0") < array[-i]
continue
else:
array[-i-1] = player.position.z.ToString("0")
Where obviously the player.position statement is from c#. I was wondering if anyone could help me translate the thought process over. It seems I need to declare an array of strings before I can use it but I am not sure.
Thanks for any help