How do I make Ad button appear only when there's an internet connection?

I don’t want anything too complicated. I’m working with Unity Ads. I have two “Game Over” menus. One Game Over menu has an Ad button and the other Game Over menu does not have an Ad button. When the player loses, one of these Game Over menus are gonna open. But that’s gonna depend on whether there’s internet connection or not.

Here’s the pseudo-code of what I’m trying to do:

if(/*there is internet connection*/)
{
   gameOverMenuWITHAdButton.gameObject.SetActive(true);
}
else
{
    gameOverMenuWITHOUTAdButton.gameObject.SetActive(true);
}

Is there any simple way to achieve this?

Give this a try …

					using (AndroidJavaClass uP = new AndroidJavaClass ("com.unity3d.player.UnityPlayer")) {
						using (AndroidJavaObject cA = uP.GetStatic<AndroidJavaObject> ("currentActivity")) {
							using (AndroidJavaClass cC = new AndroidJavaClass ("android.content.Context")) {
								using (AndroidJavaObject gAN = cA.Call<AndroidJavaObject> ("getSystemService", cC.GetStatic<string> ("CONNECTIVITY_SERVICE"))) {
									try {
										using (AndroidJavaObject gNI = gAN.Call<AndroidJavaObject> ("getActiveNetworkInfo")) {
											bool iC = gNI.Call<bool> ("isConnected");
											if (iC) { // You got a connection
												gameOverMenuWITHAdButton.gameObject.SetActive(true);
											} else { // There is no connection
												gameOverMenuWITHOUTAdButton.gameObject.SetActive(true);
											}
										}
									} catch (Exception ex) { // Something went wrong when detecting a connection
										gameOverMenuWITHOUTAdButton.gameObject.SetActive(true);
									}
								}
							}
						}
					}

If this worked out for you don’t forget to accept the answer

@The Saviour

void Start()

{
    StartCoroutine(checkInternetConnection());
}


IEnumerator checkInternetConnection()
{
    while(true)
    {
        yield return new WaitForSeconds(5);
        WWW www = new WWW("http://google.com");
        yield return www;
        if (www.error != null)
        {
            // No internet connection 
           //Do your code here
           gameOverMenuWITHOUTAdButton.gameObject.SetActive(true);
        }
        else
        {
           //internet connection is on
          //code here means
           gameOverMenuWITHAdButton.gameObject.SetActive(true);
        }
    }
}