using UnityEngine;
using System.Collections;
public class InternetTest : MonoBehaviour {
void OnGUI()
{
GUI.color = Color.green;
GUI.Label(new Rect(20, 20, 500, 200), CheckNetwork());
}
private string CheckNetwork()
{
string des = "";
//注意: 当运营商网络和WiFi/有线网同时打开时,返回ReachableViaLocalAreaNetwork
//切换网络时Application.internetReachability值不会即时变化
switch (Application.internetReachability)
{
case NetworkReachability.NotReachable:
des = "网络不可达";
break;
case NetworkReachability.ReachableViaCarrierDataNetwork:
des = "网络通过运营商数据网络是可达的";
break;
case NetworkReachability.ReachableViaLocalAreaNetwork:
des = "网络通过WiFi或有线网络是可达的";
break;
}
return des;
}
}