Skip to content

Instantly share code, notes, and snippets.

@noosxe
Created April 12, 2014 08:52
Show Gist options
  • Save noosxe/10525480 to your computer and use it in GitHub Desktop.
Save noosxe/10525480 to your computer and use it in GitHub Desktop.
Unity3D C# test for internet connection
// Unity3D C# test for internet connection
IEnumerator CheckConnection()
{
const float timeout = 10f;
float startTime = Time.timeSinceLevelLoad;
var ping = new Ping("8.8.8.8");
while (true)
{
internetAvailableText = "Checking network...";
if (ping.isDone)
{
internetAvailableText = "Network available.";
yield break;
}
if (Time.timeSinceLevelLoad - startTime > timeout)
{
internetAvailableText = "No network.";
yield break;
}
yield return new WaitForEndOfFrame();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment