Created
April 12, 2014 08:52
-
-
Save noosxe/10525480 to your computer and use it in GitHub Desktop.
Unity3D C# test for internet connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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