unity网络延迟

using UnityEngine;
using System.Collections;

public class Test_Ping : MonoBehaviour
{

    public string IP = "123.125.114.144";
    Ping ping;
    float delayTime;

    void Start()
    {
        SendPing();
    }

    void OnGUI()
    {
        GUI.color = Color.red;
        GUI.Label(new Rect(10, 10, 100, 20), "ping: " + delayTime.ToString() + "ms");

        if (null != ping && ping.isDone)
        {
            delayTime = ping.time;
            ping.DestroyPing();
            ping = null;
            Invoke("SendPing", 1.0F);//每秒Ping一次
        }
    }

    void SendPing()
    {
        ping = new Ping(IP);
    }
}

  

 

posted @ 2019-04-30 15:18  00000000O  阅读(909)  评论(0编辑  收藏  举报