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.

46 lines
1.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Networking.Server;
  5. using TMPro;
  6. using UnityEngine.SceneManagement;
  7. public class ScoreBoard : MonoBehaviour
  8. {
  9. public ClientList clientDataList;
  10. public ServerObject serverObj;
  11. public List<ClientData> ConnectedClients;
  12. public GameObject[] players = new GameObject[4];
  13. public GameObject[] scores = new GameObject[4];
  14. public string nextScene;
  15. public GameObject MainScoreboard;
  16. private void Awake()
  17. {
  18. MainScoreboard.SetActive(false);
  19. }
  20. IEnumerator displayforSeconds(GameObject display, float time)
  21. {
  22. display.SetActive (true);
  23. yield return new WaitForSeconds(time);
  24. clientDataList.server.DisconnectAllConnections();
  25. serverObj.ServerClose();
  26. SceneManager.LoadScene("MainMenu Server");
  27. }
  28. public void endGame()
  29. {
  30. ConnectedClients = clientDataList.ConnectedClients;
  31. ConnectedClients.Sort((a, b) => b.Score.CompareTo(a.Score));
  32. for (int i = 0; i < ConnectedClients.Count; i++)
  33. {
  34. players[i].GetComponent<TextMeshProUGUI>().text = ConnectedClients[i].Name;
  35. scores[i].GetComponent<TextMeshProUGUI>().text = ConnectedClients[i].Score.ToString();
  36. }
  37. StartCoroutine(displayforSeconds(MainScoreboard, 5.0f));
  38. }
  39. }