Unity ネットワークの接続状態をキャンバスに取得する
ネットワークの接続状態をキャンバスに取得する。
なぜかUnityのエディタ上だと表示されないけど、端末上では習得できる。
androidの場合はこれを
Assets/Plugins/Android/AndroidManifest.xml
に追加
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
using UnityEngine; using UnityEngine.UI; using System.Collections; public class NetworkChecker : MonoBehaviour { void Update() { switch ( Application.internetReachability ) { case NetworkReachability.NotReachable: GetComponent<Text> ().text = "ネットワークには到達不可"; break; case NetworkReachability.ReachableViaCarrierDataNetwork: GetComponent<Text> ().text = "キャリアデータネットワーク経由で到達可能"; break; case NetworkReachability.ReachableViaLocalAreaNetwork: GetComponent<Text> ().text = "Wifiまたはケーブル経由で到達可能"; break; } } }
[Unity] ネットワークの接続状態を取得する | ftvlog
Manifest.permission | Android Developers