This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
mochapine64backup/MoCha/Assets/Scripts/GetData.cs

45 lines
1,003 B
C#
Raw Normal View History

2018-04-17 14:16:10 -05:00
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
2018-04-17 15:13:19 -05:00
using UnityEngine.UI;
2018-04-17 14:16:10 -05:00
2018-04-17 15:13:19 -05:00
public class GetData : MonoBehaviour
2018-04-17 14:16:10 -05:00
{
2018-04-17 15:13:19 -05:00
//string displayText = "";
Text objectText;
2018-04-17 14:16:10 -05:00
void Start()
{
2018-04-17 15:13:19 -05:00
objectText = GetComponentInParent<Text> ();
2018-04-17 14:16:10 -05:00
}
2018-04-17 15:13:19 -05:00
public void DisplayStuff()
{
StartCoroutine (MakeRequest ());
//Debug.Log (displayText);
//objectText.text = displayText;
}
IEnumerator MakeRequest()
2018-04-17 14:16:10 -05:00
{
2018-04-17 15:13:19 -05:00
using (UnityWebRequest www = UnityWebRequest.Get("https://corder.tech/mocha/users/1"))
2018-04-17 14:16:10 -05:00
{
2018-04-17 15:13:19 -05:00
yield return www.SendWebRequest();
2018-04-17 14:16:10 -05:00
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
// Show results as text
2018-04-17 15:13:19 -05:00
//Debug.Log(www.downloadHandler.text);
objectText.text = www.downloadHandler.text;
2018-04-17 14:16:10 -05:00
// Or retrieve results as binary data
byte[] results = www.downloadHandler.data;
}
}
}
}