2016-02-04 33 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連接?在這種情況下,這個選項是無用的。 –

相關問題