zombie_mp/Assets/Scripts/Menu/leaderboard_ze.cs
2021-09-16 20:19:09 +05:30

43 lines
1.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class leaderboard_ze : MonoBehaviour
{
public Transform playerListParent;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
netPlayer[] players= FindObjectsOfType<netPlayer>();
for(int i =0; i < players.Length; i++){
Transform listItem = playerListParent.GetChild(i);
listItem.GetChild(0).GetComponent<Text>().text = players[i].pname;
listItem.GetChild(1).GetComponent<Text>().text = players[i].latency;
if(players[i].latency.Contains("ms")){
int ping = int.Parse(players[i].latency.Replace("ms",""));
if(ping < 100){
listItem.GetChild(1).GetComponent<Text>().color = Color.green;
}else if(ping < 250){
listItem.GetChild(1).GetComponent<Text>().color = Color.yellow;
}else {
listItem.GetChild(1).GetComponent<Text>().color = Color.red;
}
}
listItem.gameObject.SetActive(true);
}
for(int i =players.Length; i < playerListParent.childCount; i++){
playerListParent.GetChild(i).gameObject.SetActive(false);
}
}
}