// Update is called once per frame void Update() { if (!arduino.IsOpen) { Debug.Log("Arduino OFF"); } try { message = arduino.ReadLine(); } catch (TimeoutException) { } if (message != "") { if (racing) { String[] messageSplited = message.Split(' '); int.TryParse(messageSplited[1], out int time); if (messageSplited[0].Equals("track0:")) { racerPosition r = new racerPosition(); r.time = time; r.track = 0; racersTimes.Add(r); SaveTime(0, time); //Debug.Log(time); timesRecived++; } else if (messageSplited[0].Equals("track1:")) { racerPosition r = new racerPosition(); r.time = time; r.track = 1; racersTimes.Add(r); SaveTime(1, time); //Debug.Log(time); timesRecived++; } else if (messageSplited[0].Equals("track2:")) { racerPosition r = new racerPosition(); r.time = time; r.track = 2; racersTimes.Add(r); SaveTime(2, time); //Debug.Log(time); timesRecived++; } if (timesRecived == racers.Count) { StartCoroutine(ShowPositions()); //Debug.Log("Active Ranking"); } } } message = ""; }
public int SortByTime(racerPosition r1, racerPosition r2) { return(r1.time.CompareTo(r2.time)); }