1

I'm using AppoDeal as Ads for my game. I'm working game on Unity engine and I want allow user to have extra coins by pressing button. Also, I want hide that button if user haven't internet connection.

My sample of code which doesn't working is:

if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
    {
        coinsButton.SetActive(true);
    }
    else
    {
        coinsButton.SetActive(false);
    }
Mafii
  • 6,734
  • 1
  • 37
  • 54
mavericks
  • 115
  • 1
  • 15

2 Answers2

4

Try to inverting the logic to support wi-fi connection:

coinsButton.SetActive(Application.internetReachability!=NetworkReachability.NotReachable);
Klamore74
  • 568
  • 1
  • 6
  • 21
  • Hey, It's working very well! :)) Thank you very much my friend. Also, you opened new way of thinking :D – mavericks Mar 24 '16 at 14:33
1

This answer implements a function that pings Google, in order to check for Internet connectivity. Maybe you could find it useful.

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
     }));
 }
Community
  • 1
  • 1
Andrea
  • 5,893
  • 1
  • 29
  • 53