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.

48 lines
1.3 KiB

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