using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; using System.Linq; public class CurrentGameConnect : MonoBehaviour { private string currentGameNumber; public GameObject errorPanel; public GameObject connectingPanel; public GameObject numberInput; public GameObject selectionPanel; public GameObject nextPanel; // Start is called before the first frame update void Start() { currentGameNumber = "0"; GameObject parent = GameObject.Find("Canvas"); } // Update is called once per frame void Update() { } public void checkIfGameExistsAndNotFinished() { string gameNumber = numberInput.GetComponent().text; // SEND THE REQUEST TO SERVER // CHECK IF GAME NUMBERS EXISTS string serverUrl_check = "https://smarthubs.media.tuwien.ac.at/api/is_game_closed/" + gameNumber; connectingPanel.SetActive(true); StartCoroutine(CheckGame(serverUrl_check, gameNumber)); //CHECK IF IT IS NOT FINISHED // IF NOT //currentGameNumber = GameNumber; // ELSE ERROR WINDOW POP-UP //onnectionError.SetActive(true); } public IEnumerator CheckGame(string serverUrl, string gameNumber) { UnityWebRequest www = UnityWebRequest.Get(serverUrl); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); connectingPanel.SetActive(false); errorPanel.SetActive(true); } else { // Show results as text //Debug.Log(www.downloadHandler.text); string is_game_closed = www.downloadHandler.text; Debug.Log(is_game_closed ); // DSISPLAY GAME NUMBER // this.gameDisplayNumber.text = next_game_id; if(is_game_closed == "False") { connectingPanel.SetActive(false); currentGameNumber = gameNumber; selectionPanel.SetActive(false); nextPanel.SetActive(true); } else { connectingPanel.SetActive(false); errorPanel.SetActive(true); } } } public string GetGameNumber() { return this.currentGameNumber; } }