what I need to change so that sorting is from the smallest number to the largest, not from the largest to the smallest as it is now. Sory, but the code found on the internet and I can not find it in it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.UI;
public class PlayerTime
{
public string playerName;
public string playerTime;
public PlayerTime(string playerName, string playerTime)
{
this.playerName = playerName;
this.playerTime = playerTime;
}
public string GetFormat()
{
return playerName + "~5~" + playerTime;
}
}
public class TimeBoard : MonoBehaviour
{
public int timeCount = 10;
[Header("SAVE PANEL")]
public InputField inputName;
public InputField inputTime;
[Header("TIME DISPLAY")]
public GameObject timeObject;
public GameObject timeRoot;
public Text textName, textTime;
static TimeBoard timeBoard;
static string separator = "~5~";
void Start()
{
timeBoard = this;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.S))
{
}
if (Input.GetKeyDown(KeyCode.P))
{
List<PlayerTime> playerTime = GetTime();
foreach (PlayerTime p in playerTime)
{
print(p.playerName + " " + p.playerTime);
}
}
}
public void SaveTimeNow()
{
SaveTime(inputName.text, inputTime.text);
}
public void ShowTime()
{
StartCoroutine(CoShowTime());
}
IEnumerator CoShowTime()
{
while (timeRoot.transform.childCount > 0)
{
Destroy(timeRoot.transform.GetChild(0).gameObject);
yield return null;
}
List<PlayerTime> playerTime = GetTime();
foreach (PlayerTime time in playerTime)
{
textName.text = time.playerName;
textTime.text = time.playerTime.ToString();
GameObject instantiatedTime = Instantiate(timeObject);
instantiatedTime.SetActive(true);
instantiatedTime.transform.SetParent(timeRoot.transform);
}
}
public static void SaveTime(string name, string time)
{
List<PlayerTime> playerTime = new List<PlayerTime>();
for (int i = 0; i < timeBoard.timeCount; i++)
{
if (PlayerPrefs.HasKey("Time" + i))
{
string[] timeFormat = PlayerPrefs.GetString("Time" + i).Split(new string[] { separator }, System.StringSplitOptions.RemoveEmptyEntries);
playerTime.Add(new PlayerTime(timeFormat[0], timeFormat[1]));
}
else
{
break;
}
}
if (playerTime.Count < 1)
{
PlayerPrefs.SetString("Time0", name + separator + time);
print("terpanggil");
return;
}
playerTime.Add(new PlayerTime(name, time));
playerTime = playerTime.OrderByDescending(o => o.playerTime).ToList();
for (int i = 0; i < timeBoard.timeCount; i++)
{
if (i >= playerTime.Count) { break; }
PlayerPrefs.SetString("Time" + i, playerTime[i].GetFormat());
}
}
public List<PlayerTime> GetTime()
{
List<PlayerTime> playerTime = new List<PlayerTime>();
for (int i = 0; i < timeBoard.timeCount; i++)
{
if (PlayerPrefs.HasKey("Time" + i))
{
string[] timeFormat = PlayerPrefs.GetString("Time" + i).Split(new string[] { separator }, System.StringSplitOptions.RemoveEmptyEntries);
playerTime.Add(new PlayerTime(timeFormat[0], timeFormat[1]));
}
else
{
break;
}
}
return playerTime;
}
}