Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to check whether the device is connected to internet or not in Unity

Posted on February 8, 2022February 8, 2022 by Habibie

If you want to check is the Unity game running in a device connected to internet or not, you can call this coroutine function:

IEnumerator CheckInternetConnection() {
        using (UnityWebRequest webRequest = UnityWebRequest.Get("https://googleads.g.doubleclick.net/"))
        {
            // Request and wait for the desired page.
            yield return webRequest.SendWebRequest();
            switch (webRequest.result)
            {
                case UnityWebRequest.Result.ConnectionError:
                    Debug.Log("No Internet");
                    break;
                case UnityWebRequest.Result.DataProcessingError:
                    Debug.Log("No Internet");
                    break;
                case UnityWebRequest.Result.ProtocolError:
                    Debug.Log("No Internet");
                    break;
                case UnityWebRequest.Result.Success:
                    Debug.Log("Connected to the Internet");
                    break;
            }
        }
    }

Simply call that coroutine function like this:

StartCoroutine(CheckInternetConnection());

Then wait for a message in your Unity console about internet connection.

Don’t forget to use Networking namespace:

using UnityEngine.Networking;

Post Views: 436
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme