You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

60 lines
1.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Networking.Server;
public class ScoreDisplay : MonoBehaviour
{
public List<ClientData> ConnectedClients;
public ClientList clientDataList;
public GameObject levelScoreboard;
public GameObject[] players = new GameObject[4];
public GameObject[] scores = new GameObject[4];
public ScoreBoard mainscoreboard;
/// <summary>
/// calculates and assigns scores in desc order, call coroutine
/// </summary>
///
/// <summary>
/// couroutine to display level scores
/// </summary>
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<TextMeshProUGUI>().text = ConnectedClients[i].Name;
scores[i].GetComponent<TextMeshProUGUI>().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();
}
}