2016-02-04 31 views

回答

4

幸运的是团结正是这种简单,

的Android

enter image description here

的iOS

enter image description here

打开生成设置对话框(文件菜单)

点击PlayerSettings,看督察,对OtherSettings面板,

向下滚动,以及网络连接...

...,然后选择您想要的模式!

就是这样。


高级的问题:注意过,这个非常有用的电话...

http://docs.unity3d.com/ScriptReference/Application-internetReachability.html

然而这是相当复杂使用;这是实施这个项目的一个重大项目。在更复杂的项目,也考虑

http://docs.unity3d.com/ScriptReference/NetworkReachability.html

如果你想获得这些,与网上公布的众多首发的例子开始,例如https://stackoverflow.com/a/24351716/294884(这个人理智地使用谷歌著名的DNS为“网站如果互联网存在,你几乎可以在理论上达到理论上的效果 - “当你试图实现这个时,只是需要处理的许多问题之一)。


最后,请注意,在一定意义上做到这一点的一种方式是

  • 只是去上网了一些你知道的页面有如果,等待足够的后

  • 时间量为 (多长时间?也许是5秒 - 我不知道) 你没有得到结果,那么假设没有 体面的互联网连接。

下面是实际的代码,让你去的,如果你从来没有在统一之前做了WWW

private string testUrl = "http://someTestSite.com/whatever.html"; 

private void CheckIfWeCanGetNetPagesAtAll() 
    { 
    StartCoroutine(_Check()); 
    } 

private IEnumerator _Check() 
    { 
    WWW w = new WWW(testUrl.URLAntiCacheRandomizer()); 
    yield return w; 
    if (w.error != null) 
     { 
     Debug.Log(">>> could not get internet test page, Error .. " +w.error); 
     // bring up error message for user, that the app canot be used 
     // just no because you have no internet access. 
     } 
    else 
     { 
     // no problems 
     } 

    // not shown here ... you may prefer to implement your own time-out 
    // rather than just waiting for WWW to time-out, which can be long. 
    } 
+0

但是,您只能在Android中看到此设置。所以我认为这不是一个普遍的答案。我对吗? –

+1

'需要持久Wifi'for ios –

+0

大多数情况下应该可以,但如果iPhone或iPad与互联网连接但不通过WIFI连接?在这种情况下,这个选项是无用的。 –

相关问题