Ping

作者:追风剑情 发布于:2014-7-14 22:24 分类:Unity3d

using UnityEngine;
using System.Collections;

public class Test_Ping : MonoBehaviour {

	public string IP = "220.181.111.86";
	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);
	}
}
把以上脚本挂在主摄像机上。
运行效果
Ping.png 

标签: Ping

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号