版本:Unity 6 (6000.0)
语言中文
  • C#

NetworkReachability.ReachableViaLocalAreaNetwork

提出变更建议

提交成功!

感谢您帮助我们提升 Unity 文档的质量。虽然我们无法接受所有投稿请求,但我们会认真阅读用户提出的每条变更建议,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,无法提交您的变更建议。请在几分钟后重试。感谢您抽出时间帮助我们提升 Unity 文档的质量。

关闭

取消

描述

可通过 WiFi 或网线连接到网络。

//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."; } } }