Pimeko

Untitled

Apr 7th, 2021
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6.  
  7. [System.Serializable]
  8. public class Data
  9. {
  10.     public string _id;
  11.     public string name;
  12. }
  13.  
  14. [System.Serializable]
  15. public class Datas
  16. {
  17.     public Data[] datas;
  18. }
  19.  
  20. public class APIController : MonoBehaviour
  21. {
  22.     void Start()
  23.     {
  24.         StartCoroutine(GetRequest("URL"));
  25.     }
  26.  
  27.     IEnumerator GetRequest(string uri)
  28.     {
  29.         using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
  30.         {
  31.             yield return webRequest.SendWebRequest();
  32.  
  33.             if (!webRequest.isNetworkError)
  34.             {
  35.                 Datas result = JsonUtility.FromJson<Datas>("{\"datas\":" + webRequest.downloadHandler.text + "}");
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment