예제 #1
0
    public IEnumerator GetTopScores(int levelID, Text textbox)
    {
        WWWForm form = new WWWForm();

        form.AddField("LevelID", levelID);
        form.AddField("Limit", limit);

        UnityWebRequest www = UnityWebRequest.Post(TopScoresURL, form);

        yield return(www.SendWebRequest());

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log("an error occured when feching scores from " + levelID + "...\n" + www.error);
            textbox.text = "\nAn Error occured...\n" + www.error;
        }
        else
        {
            Debug.Log("sucessfully fetched from " + levelID);
            string jsonString = www.downloadHandler.text;
            Debug.Log(jsonString);
            ScoreList scores = new ScoreList();
            scores = ScoreList.CreateFromJSON(jsonString);

            textbox.text = scores.ToString();
        }
    }