Answers for "unity callback"

C#
1

unity callback

void callApi()
    {
        StartCoroutine(FetchData(ApiAction));
    }
    
    string url = "https://postman-echo.com/get?foo1=bar1";
    IEnumerator FetchData(System.Action<string, bool> callback)
    {
        UnityWebRequest getData = UnityWebRequest.Get(url);
        yield return getData.SendWebRequest();
        if (getData.isDone == false || getData.error != null)
            callback(getData.error, false);
        else
            callback(getData.downloadHandler.text, true);
    }
    void ApiAction(string response, bool isSuccess)
    {
        if (isSuccess)
            Debug.Log(response);
    }
Posted by: Guest on March-22-2021
0

unity callback

void callApi(){
        StartCoroutine(FetchData((response, isSuccess) =>
        {
            if (isSuccess)
            {
                Debug.Log(response);
            }
        }));
    }
Posted by: Guest on March-22-2021

C# Answers by Framework

Browse Popular Code Answers by Language