Version: 2017.3

NetworkReachability

enumeration

切换到手册

描述

描述网络可访问性选项。

描述设备上有哪些可用于连接到 Internet 的选项(如果有)。

//Attach this script to a GameObject
//This script checks the device’s ability to reach the internet and outputs it to the console window

using UnityEngine;

public class Example : MonoBehaviour { string m_ReachabilityText;

void Update() { //Output the network reachability to the console window Debug.Log("Internet : " + m_ReachabilityText); //Check if the device cannot reach the internet if (Application.internetReachability == NetworkReachability.NotReachable) { //Change the Text m_ReachabilityText = "Not Reachable."; } //Check if the device can reach the internet via a carrier data network else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork) { m_ReachabilityText = "Reachable via carrier data network."; } //Check if the device can reach the internet via a LAN else if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) { m_ReachabilityText = "Reachable via Local Area Network."; } } }

变量

NotReachable无法访问网络。
ReachableViaCarrierDataNetwork可通过运营商数据网络访问网络。
ReachableViaLocalAreaNetwork可通过 WiFi 或有线网络访问网络。