我正在 Unity 中编写一个简单的代码,以检查我是否能够通过我的应用程序访问网站。这是我写的代码:
IEnumerator CheckInternetPing()
{
WWW wwwInternet = new WWW("http://google.com");
yield return wwwInternet;
if (wwwInternet.bytesDownloaded == 0)
{
//yield return new WaitForSeconds(1f);
Debug.Log("Not Connected to Internet");
}
else
{
Debug.Log("Connected to Internet");
internetMenu.SetActive(false);
}
}
Run Code Online (Sandbox Code Playgroud)
我发现了一个错误,如果我在互联网上运行它,它会显示“已连接”,但是当我关闭互联网并立即运行该应用程序时,它不会记录任何内容。仅当我再次重新启动应用程序时,它才会显示“未连接”。有谁知道为什么它在第一次没有记录任何内容?谢谢