unity显示网络延迟ping
Posted 任雪松
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity显示网络延迟ping相关的知识,希望对你有一定的参考价值。
- 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);
- }
- }
以上是关于unity显示网络延迟ping的主要内容,如果未能解决你的问题,请参考以下文章