Skip to content

Instantly share code, notes, and snippets.

@riveranb
Last active July 6, 2019 12:07
Show Gist options
  • Select an option

  • Save riveranb/14a8d87759fa54114858faa06c0baa68 to your computer and use it in GitHub Desktop.

Select an option

Save riveranb/14a8d87759fa54114858faa06c0baa68 to your computer and use it in GitHub Desktop.
C# check for internet connection
// API doc for "WWW": https://docs.unity3d.com/ScriptReference/WWW.html
public static IEnumerator InternetConnectTrying(Action<bool> action, float secs = 1)
{
WWW www = new WWW("https://www.google.com");
yield return www;
yield return new WaitForSeconds(secs);
if (www.error != null)
{
_cacheHttpError = www.error;
}
// action(bool): true means internec connection exists
action.Invoke(www.responseHeaders != null && www.responseHeaders.Count > 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment