在Unity中判斷手機是否有網和網路型別
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class IsConnect : MonoBehaviour
{
public GameObject tt2;
/// <summary>
/// 網路可用否
/// </summary>
public static bool NetAvailable
{
get
{
return Application.internetReachability != NetworkReachability.NotReachable;
}
}
/// <summary>
/// WIFI否
/// </summary>
public static bool IsWifi
{
get
{
return Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork;
}
}
void Update()
{
if (!NetAvailable)
{
tt2.GetComponent<Text>().text = "無網路連線";
}
else
{
tt2.GetComponent<Text>().text = "有網路,資料";
if (IsWifi)
{
tt2.GetComponent<Text>().text = "有網路,WIFI";
}
else tt2.GetComponent<Text>().text = "有網路,資料";
}
}
}