在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 = "有网络,数据";

        }

    }


}
 

猜你喜欢

转载自blog.csdn.net/Hu_jinbo/article/details/81169589