Example #1
0
    IEnumerator LoginUser(string email, string password)
    {
        WWWForm form = new WWWForm();

        form.AddField("email", email);
        form.AddField("password", password);

        webRequest = UnityWebRequest.Post($"{webService}/user/login", form);

        yield return(webRequest.SendWebRequest());

        if (webRequest.isNetworkError)
        {
            Debug.Log("Error en la peticion");
        }
        else
        {
            if (webRequest.responseCode == 200)
            {
                var json = JSON.Parse(webRequest.downloadHandler.text);
                PlayerStorage.SaveId(json["user"]["email"], json["user"]["_id"]);
                SceneManager.LoadScene("Main");
            }
            else
            {
                Debug.Log("User o password incorrecto");
            }
        }
    }