Test_Ping.cs 630 B

12345678910111213141516171819202122232425262728293031323334
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Test_Ping : MonoBehaviour
  4. {
  5. public string IP = "192.168.80.59";
  6. Ping ping;
  7. float delayTime;
  8. void Start()
  9. {
  10. SendPing();
  11. }
  12. void OnGUI()
  13. {
  14. GUI.color = Color.red;
  15. GUI.Label(new Rect(10, 10, 100, 20), "ping: " + delayTime.ToString() + "ms");
  16. if (null != ping && ping.isDone)
  17. {
  18. delayTime = ping.time;
  19. ping.DestroyPing();
  20. ping = null;
  21. Invoke("SendPing", 1.0F);//ÿÃëPingÒ»´Î
  22. }
  23. }
  24. void SendPing()
  25. {
  26. ping = new Ping(IP);
  27. }
  28. }