Skip to content

Instantly share code, notes, and snippets.

@nndwn
Last active May 6, 2024 00:51
Show Gist options
  • Save nndwn/11436e416c40c9a6753e09330f2f836f to your computer and use it in GitHub Desktop.
Save nndwn/11436e416c40c9a6753e09330f2f836f to your computer and use it in GitHub Desktop.
public class CheckConnection : MonoBehaviour
{
private void Start()
{
StartCoroutine(IsConnected(connected =>
{
if (connected)
{
Debug.Log("connented in internet")
}else
{
Debug.Log( "cant connected internet")
}
}));
}
public IEnumerator IsConnected(Action<bool> action)
{
var isConnected = false;
var request = UnityWebRequest.Get("https://www.nndwn.my.id/cultureshock/privacy");
request.method = "HEAD";
request.timeout = 3;
yield return request.SendWebRequest();
if (request.responseCode == 200)
{
isConnected = true;
}
action(isConnected);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment