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.

45 lines
1.6 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. public class ScoreBoard : MonoBehaviour
  9. {
  10. public ConnectionHandler clientDataList;
  11. public List<ClientData> ConnectedClients;
  12. public bool endOfGame = false;
  13. public GameObject FirstPlaceName;
  14. public GameObject FirstPlaceScore;
  15. public GameObject SecondPlaceName;
  16. public GameObject SecondPlaceScore;
  17. public GameObject ThirdPlaceName;
  18. public GameObject ThirdPlaceScore;
  19. public GameObject FourthPlaceName;
  20. public GameObject FourthPlaceScore;
  21. void Update()
  22. {
  23. if (Input.GetKeyDown("m")){
  24. endGame();
  25. }
  26. }
  27. public void endGame()
  28. {
  29. ConnectedClients = clientDataList.ConnectedClients;
  30. ConnectedClients.Sort((a, b) => b.Score.CompareTo(a.Score));
  31. FirstPlaceName.GetComponent<TextMeshProUGUI>().text = ConnectedClients[0].Name;
  32. FirstPlaceScore.GetComponent<TextMeshProUGUI>().text = ConnectedClients[0].Score.ToString();
  33. SecondPlaceName.GetComponent<TextMeshProUGUI>().text = ConnectedClients[1].Name;
  34. SecondPlaceScore.GetComponent<TextMeshProUGUI>().text = ConnectedClients[1].Score.ToString();
  35. ThirdPlaceName.GetComponent<TextMeshProUGUI>().text = ConnectedClients[2].Name;
  36. ThirdPlaceScore.GetComponent<TextMeshProUGUI>().text = ConnectedClients[2].Score.ToString();
  37. FourthPlaceName.GetComponent<TextMeshProUGUI>().text = ConnectedClients[3].Name;
  38. FourthPlaceScore.GetComponent<TextMeshProUGUI>().text = ConnectedClients[3].Score.ToString();
  39. }
  40. //after 10 seconds load next scene/game
  41. }