Skip to content

Instantly share code, notes, and snippets.

@rdeioris
Created April 1, 2019 18:05
Show Gist options
  • Save rdeioris/558daac7cfea8bf256ba188018a4b4a5 to your computer and use it in GitHub Desktop.
Save rdeioris/558daac7cfea8bf256ba188018a4b4a5 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class TalkWithFlask : MonoBehaviour
{
[System.Serializable]
class Dumb
{
public float boh;
public string hello;
public int number;
}
UnityWebRequestAsyncOperation asyncOp;
delegate void State();
State currentState;
void MakeMatchmaking()
{
UnityWebRequest request = new UnityWebRequest("http://robertoaiv.pythonanywhere.com/hello");
request.downloadHandler = new DownloadHandlerBuffer();
asyncOp = request.SendWebRequest();
currentState = CheckMatchmaking;
}
void CheckMatchmaking()
{
if (asyncOp.isDone)
{
Debug.Log(asyncOp.webRequest.responseCode);
Debug.Log(asyncOp.webRequest.downloadHandler.text);
Dumb dumb = JsonUtility.FromJson<Dumb>(asyncOp.webRequest.downloadHandler.text);
Debug.Log(dumb.boh);
currentState = MakePoll;
}
}
void MakePoll()
{
}
void Start()
{
currentState = MakeMatchmaking;
}
void Update()
{
currentState();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment