-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorldLoader.cs
36 lines (28 loc) · 909 Bytes
/
WorldLoader.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class WorldLoader : MonoBehaviour
{
// Start is called before the first frame update
void Start() {
StartCoroutine(PostRequest("http://127.0.0.1:8000/api/test-unity"));
}
IEnumerator PostRequest(string url) {
WWWForm form = new WWWForm();
form.AddField("myField", "myData");
UnityWebRequest www = UnityWebRequest.Post(url, form);
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
else {
string response = www.downloadHandler.text;
Debug.Log("Form upload complete! Text: " + response);
yield return response;
}
}
// Update is called once per frame
void Update() {
}
}