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

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5. using Networking.Server;
  6. public class ScoreDisplay : MonoBehaviour
  7. {
  8. public List<ClientData> ConnectedClients;
  9. public ClientList clientDataList;
  10. public GameObject levelScoreboard;
  11. public GameObject[] players = new GameObject[4];
  12. public GameObject[] scores = new GameObject[4];
  13. public ScoreBoard mainscoreboard;
  14. /// <summary>
  15. /// calculates and assigns scores in desc order, call coroutine
  16. /// </summary>
  17. ///
  18. /// <summary>
  19. /// couroutine to display level scores
  20. /// </summary>
  21. IEnumerator displayforSeconds(GameObject display, float time)
  22. {
  23. display.SetActive(true);
  24. yield return new WaitForSeconds(time);
  25. display.SetActive(false);
  26. mainscoreboard.endGame();
  27. }
  28. public void levelComplete()
  29. {
  30. ConnectedClients = clientDataList.ConnectedClients;
  31. ConnectedClients.Sort((a, b) => b.SceneScore.CompareTo(a.SceneScore));
  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].SceneScore.ToString();
  36. }
  37. int assignedPoints = 3;
  38. for (int i = 0; i < ConnectedClients.Count; i++)
  39. {
  40. ConnectedClients[i].Score += assignedPoints;
  41. assignedPoints--;
  42. }
  43. StartCoroutine(displayforSeconds(levelScoreboard, 5.0f));
  44. }
  45. public void Start()
  46. {
  47. levelComplete();
  48. }
  49. }