45 lines
969 B
C#
45 lines
969 B
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class PingDisplay : MonoBehaviour
|
|||
|
{
|
|||
|
public Text pingText; // <20><>ʾ<EFBFBD>ӳٵ<D3B3>UI Text
|
|||
|
private int pingValue = 100; // ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ֵ
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
pingText.text = $"<22><><EFBFBD><EFBFBD><EFBFBD>ӳ٣<D3B3>{pingValue}ms";
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
if (pingValue <= 149)
|
|||
|
{
|
|||
|
pingText.color = Color.green; // <20><>ɫ
|
|||
|
}
|
|||
|
else if (pingValue <= 399)
|
|||
|
{
|
|||
|
pingText.color = new Color(1f, 0.92f, 0.016f); // <20><>ɫ (RGB<47><42><EFBFBD><EFBFBD>)
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
pingText.color = Color.red; // <20><>ɫ
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void SetPingValue(int _pingValue)
|
|||
|
{
|
|||
|
pingValue = _pingValue;
|
|||
|
}
|
|||
|
|
|||
|
// ģ<><C4A3><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ӳٵķ<D9B5><C4B7><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD>滻Ϊ<E6BBBB><CEAA>ʵ<EFBFBD>ӳٻ<D3B3>ȡ<EFBFBD><EFBFBD>
|
|||
|
int GetPingValue()
|
|||
|
{
|
|||
|
// ʾ<><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
|||
|
return Random.Range(1, 500);
|
|||
|
}
|
|||
|
}
|