- public class PintTest : MonoBehaviour {
-
public string ip = string.Empty;//IP地址
-
private bool iswork = false;//是否有网络通信
-
PingReplay re;
-
void Start()
-
{
-
ip = "61.135.169.121"; // 百度
-
InvokeRepeating("SendPing",1,3);
-
}
-
void Update()
-
{
-
if(re!=null){
-
if (re.Status==IPStatus.TimeOut)
-
{
-
Debug.Log(“网络已经断开”);
-
}
-
else if(re.Status==IPStatus.Success)
-
{
-
Debug.Log(“网络正常”);
-
}
-
}
-
}
-
void SendPing()
-
{
-
ping = new System.Net.NetworkInformation.Ping();
-
re=ping.Send(ip,3000);
-
}
- }
Unity3d:检测本地是否和服务器连接正常
最新推荐文章于 2022-06-22 11:14:07 发布