In fact, I do not believe Network.TestConnection() is a suitable tool for this work. According to the documentation , it seems to me that it is designed to test the health of NAT and the availability of your client by IP, but you want to check if you have a common Internet connection.
Here is the solution I found in Unity pixel_fiend user answers that just tests the website to determine if the user has a connection. One of the advantages of this code is that it uses IEnumerator for asynchronous operation, so the connection test will not delay the rest of your application:
IEnumerator checkInternetConnection(Action<bool> action){ WWW www = new WWW("http://google.com"); yield return www; if (www.error != null) { action (false); } else { action (true); } } void Start(){ StartCoroutine(checkInternetConnection((isConnected)=>{
You can change the website to any other or change the code so that it returns success if any of several sites is available. In fact, there is no way to verify the authenticity of an Internet connection without trying to connect to a specific site on the Internet, so pinging one or more websites like this is probably the best choice for determining an Internet connection.
source share