I am attempting to set up a web request call with how to handle the information but the way that I know how to set it up says it is depreciated as in error CS0618 in the image attached. so I changed the formating and then it gives me a new error CS0176. Heres the code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public static class WebRequests
{
private class WebRequestsMonoBehaviour : MonoBehaviour { }
private static WebRequestsMonoBehaviour webRequestsMonoBehaviour;
private static void Init()
{
if (webRequestsMonoBehaviour == null)
{
GameObject gameObject = new GameObject("WebRequests");
webRequestsMonoBehaviour = gameObject.AddComponent<WebRequestsMonoBehaviour>();
}
}
public static void Get(string url, Action<string> onError, Action<string> onSuccess)
{
Init();
webRequestsMonoBehaviour.StartCoroutine(GetCoroutine(url, onError, onSuccess));
}
public static IEnumerator GetCoroutine(string url, Action<string> onError, Action<string> onSuccess)
{
using (UnityWebRequest unityWebRequest = UnityWebRequest.Get(url))
{
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.result == unityWebRequest.result.ConnectionError || unityWebRequest.result == unityWebRequest.result.ProtocolError)
{
onError(unityWebRequest.error);
}
else
{
onSuccess(unityWebRequest.downloadHandler.text);
}
}
}
public static void GetTexture(string url, Action<string> onError, Action<Texture2D> onSuccess)
{
Init();
webRequestsMonoBehaviour.StartCoroutine(GetTextureCoroutine(url, onError, onSuccess));
}
private static IEnumerator GetTextureCoroutine(string url, Action<string> onError, Action<Texture2D> onSuccess)
{
using (UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(url))
{
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.isNetworkError || unityWebRequest.result == unityWebRequest.Result.ProtocolError)
{
onError(unityWebRequest.error);
}
else
{
DownloadHandlerTexture downloadHandlerTexture = unityWebRequest.downloadHandler as DownloadHandlerTexture;
onSuccess(downloadHandlerTexture.texture);
}
}
}
}
