IEnumerator Register()
    {
        var register = new AuthReq(nameField.text, passwordField.text);

        UnityWebRequest uwr = UnityWebRequest.Post("http://localhost/sqlconnect/register.php", register.getJsonWWWForm());

        yield return(uwr.SendWebRequest());

        if (uwr.isNetworkError || uwr.isHttpError)
        {
            Debug.Log(uwr.error);
        }

        Debug.Log(uwr.downloadHandler.text);

        try {
            var response = AuthResp.fromJson(uwr.downloadHandler.text);

            if (response.NoError)
            {
                Debug.Log("User created successfully");
                UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu");
            }
            else
            {
                Debug.Log("User creation failed. Error #" + response.code + " details: " + response.details);
            }
        } catch (Exception e) {
            Debug.Log("Bad json: " + e);
        }
    }
Beispiel #2
0
    IEnumerator SavePlayerData()
    {
        UnityWebRequest uwr = UnityWebRequest.Post("http://localhost/sqlconnect/savedata.php", DBManager.player.getJsonWWWForm());

        yield return(uwr.SendWebRequest());

        if (uwr.isNetworkError || uwr.isHttpError)
        {
            Debug.Log(uwr.error);
        }

        Debug.Log(uwr.downloadHandler.text);

        try {
            var response = AuthResp.fromJson(uwr.downloadHandler.text);

            if (response.NoError)
            {
                Debug.Log("User data saved successfully");
            }
            else
            {
                Debug.Log("User data save failed. Error #" + response.code + " details: " + response.details);
            }
        } catch (Exception e) {
            Debug.Log("Bad json: " + e);
        }

        DBManager.LogOut();
        UnityEngine.SceneManagement.SceneManager.LoadScene("mainmenu");
    }