IEnumerator GetRoomRequest(string uri, RoomLobbyController rlc) { bool requestFinished = false; bool requestErrorOccurred = false; UnityWebRequest request = UnityWebRequest.Get(uri); yield return(request.Send()); if (request.isNetworkError) { Debug.Log("Something went wrong, and returned error: " + request.error); requestErrorOccurred = true; } else { if (!requestErrorOccurred) { yield return(null); // process results var N = JSON.Parse(request.downloadHandler.text); Debug.Log(request.downloadHandler.text); currentRoom.id = N["room"]["id"].AsInt; currentRoom.name = N["room"]["name"]; currentRoom.chancellor_id = N["room"]["chancellor_id"].AsInt; currentRoom.president_id = N["room"]["president_id"].AsInt; currentRoom.disorder_count = N["room"]["disorder_count"].AsInt; currentRoom.fascist_policy_count = N["room"]["fascist_policy_count"].AsInt; currentRoom.liberal_policy_count = N["room"]["liberal_policy_count"].AsInt; rlc.SetRoomName(); } } }
public void GetNewRoom(RoomLobbyController rlc) { string uri = url + "/rooms/new.json"; StartCoroutine(GetRoomRequest(uri, rlc)); }