check for internet connection unity code example
Example 1: unity check if device has wifi
public bool internetConnectivity()
{
UnityWebRequest request = UnityWebRequest.Get("https://www.google.com/");
request.SendWebRequest();
if (request.error != null)
{
Debug.LogWarning("No internet connection");
return false;
}
else
{
return true;
}
}
Example 2: unity test network connection
if (Application.internetReachability == 0)
{
Debug.LogWarning("No internet connection");
}
if (Application.internetReachability == 1)
{
Debug.LogWarning("Connected to mobile carrier");
}
if (Application.internetReachability == 3)
{
Debug.LogWarning("Connected to WiFi");
}