12345678910111213141516171819202122232425262728293031323334 |
- using UnityEngine;
- using System.Collections;
- public class Test_Ping : MonoBehaviour
- {
- public string IP = "192.168.80.59";
- 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);
- }
- }
|