using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using Networking.Server; public class ScoreDisplay : MonoBehaviour { public List ConnectedClients; public ClientList clientDataList; public GameObject levelScoreboard; public GameObject[] players = new GameObject[4]; public GameObject[] scores = new GameObject[4]; public ScoreBoard mainscoreboard; /// /// calculates and assigns scores in desc order, call coroutine /// /// /// /// couroutine to display level scores /// IEnumerator displayforSeconds(GameObject display, float time) { display.SetActive(true); yield return new WaitForSeconds(time); display.SetActive(false); mainscoreboard.endGame(); } public void levelComplete() { ConnectedClients = clientDataList.ConnectedClients; ConnectedClients.Sort((a, b) => b.SceneScore.CompareTo(a.SceneScore)); for (int i = 0; i < ConnectedClients.Count; i++) { players[i].GetComponent().text = ConnectedClients[i].Name; scores[i].GetComponent().text = ConnectedClients[i].SceneScore.ToString(); } int assignedPoints = 3; for (int i = 0; i < ConnectedClients.Count; i++) { ConnectedClients[i].Score += assignedPoints; assignedPoints--; } StartCoroutine(displayforSeconds(levelScoreboard, 5.0f)); } public void Start() { levelComplete(); } }