【问题标题】:Show button if user has internet connection [closed]如果用户有互联网连接,则显示按钮[关闭]
【发布时间】:2016-03-24 22:26:30
【问题描述】:

我将 AppoDeal 用作我的游戏的广告。我正在 Unity 引擎上开发游戏,我希望允许用户通过按下按钮来获得额外的硬币。另外,如果用户没有互联网连接,我想隐藏该按钮。

我的无效代码示例是:

if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
    {
        coinsButton.SetActive(true);
    }
    else
    {
        coinsButton.SetActive(false);
    }

【问题讨论】:

    标签: c# unity3d ads


    【解决方案1】:

    尝试反转逻辑支持wi-fi连接:

    coinsButton.SetActive(Application.internetReachability!=NetworkReachability.NotReachable);
    

    【讨论】:

    • 嘿,效果很好! :)) 非常感谢你,我的朋友。此外,您开辟了新的思维方式:D
    【解决方案2】:

    This answer 实现了 ping Google 的功能,以检查 Internet 连接。也许你会发现它很有用。

    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)=>{
             // handle connection status here
         }));
     }
    

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2018-09-16
      • 1970-01-01
      相关资源
      最近更新 更多