/// <summary> /// Wait for loading public IP from https://ifconfig.co/ip /// </summary> /// <param name="callback"></param> /// <returns></returns> private IEnumerator GetPublicIPCoroutine(GetPublicIPResult callback) { UnityWebRequest www = UnityWebRequest.Get("https://ifconfig.co/ip"); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { callback?.Invoke(null, www.error); Debug.LogError(www.error); } else { var ipInfo = www.downloadHandler.text; callback?.Invoke(ipInfo, string.Empty); } }
/// <summary> /// Wait for loading public IP from https://ifconfig.co/ip /// </summary> /// <param name="callback"></param> /// <returns></returns> private IEnumerator GetPublicIPCoroutine(GetPublicIPResult callback) { using (UnityWebRequest www = UnityWebRequest.Get("https://ifconfig.co/ip")) { yield return(www.SendWebRequest()); if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.DataProcessingError || www.result == UnityWebRequest.Result.ProtocolError) { callback?.Invoke(null, www.error); Debug.LogError(www.error); } else if (www.result == UnityWebRequest.Result.Success) { var ipInfo = www.downloadHandler.text; callback?.Invoke(ipInfo, string.Empty); } } }