leaderboard_ze.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class leaderboard_ze : MonoBehaviour
  6. {
  7. public Transform playerListParent;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. }
  12. // Update is called once per frame
  13. void Update()
  14. {
  15. netPlayer[] players= FindObjectsOfType<netPlayer>();
  16. for(int i =0; i < players.Length; i++){
  17. Transform listItem = playerListParent.GetChild(i);
  18. listItem.GetChild(0).GetComponent<Text>().text = players[i].pname;
  19. listItem.GetChild(1).GetComponent<Text>().text = players[i].latency;
  20. if(players[i].latency.Contains("ms")){
  21. int ping = int.Parse(players[i].latency.Replace("ms",""));
  22. if(ping < 100){
  23. listItem.GetChild(1).GetComponent<Text>().color = Color.green;
  24. }else if(ping < 250){
  25. listItem.GetChild(1).GetComponent<Text>().color = Color.yellow;
  26. }else {
  27. listItem.GetChild(1).GetComponent<Text>().color = Color.red;
  28. }
  29. }
  30. listItem.gameObject.SetActive(true);
  31. }
  32. for(int i =players.Length; i < playerListParent.childCount; i++){
  33. playerListParent.GetChild(i).gameObject.SetActive(false);
  34. }
  35. }
  36. }