首页 > 编程语言 > 详细

unity显示网络延迟ping

时间:2017-09-23 23:53:00      阅读:1190      评论:0      收藏:0      [点我收藏+]
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Test_Ping : MonoBehaviour {
  5.  
  6. public string IP = "220.181.111.86";
  7. Ping ping;
  8. float delayTime;
  9.  
  10. void Start(){
  11. SendPing ();
  12. }
  13.  
  14. void OnGUI () {
  15. GUI.color = Color.red;
  16. GUI.Label(new Rect(10, 10, 100, 20), "ping: "+delayTime.ToString()+"ms");
  17.  
  18. if (null != ping && ping.isDone) {
  19. delayTime = ping.time;
  20. ping.DestroyPing();
  21. ping = null;
  22. Invoke ("SendPing", 1.0F);//每秒Ping一次
  23. }
  24. }
  25.  
  26. void SendPing()
  27. {
  28. ping = new Ping(IP);
  29. }
  30. }

unity显示网络延迟ping

原文:http://www.cnblogs.com/rxs123/p/7583497.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!