/// <summary> /// Posts the player's money, team, first time boolean and name to the PlayerInfo database where it matches the player ID /// </summary> /// <param name="logout">Determines if the coroutine is being called alongside a logout action. If true, delete all player prefs</param> /// <returns></returns> IEnumerator StorePlayerDataRoutine(bool logout) { WWWForm form = new WWWForm(); form.AddField("player_id", GameSaveUtility.GetID()); form.AddField("player_money", GameSaveUtility.GetTotalBalance()); if (GameSaveUtility.GetChapProgress(1)) { form.AddField("progress1", 1); } if (GameSaveUtility.GetChapProgress(2)) { form.AddField("progress2", 1); } if (GameSaveUtility.GetChapProgress(3)) { form.AddField("progress3", 1); } using (UnityWebRequest www = UnityWebRequest.Post(path + "updateplayerinfo.php", form)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); StringBuilder sb = new StringBuilder(); foreach (System.Collections.Generic.KeyValuePair <string, string> dict in www.GetResponseHeaders()) { sb.Append(dict.Key).Append(": \t[").Append(dict.Value).Append("]\n"); } // Print Headers #if (UNITY_EDITOR) Debug.Log(sb.ToString()); #endif if (www.GetResponseHeaders().Count > 0 && www.GetResponseHeaders().ContainsKey("userUpdated")) { if (www.GetResponseHeaders()["userUpdated"] == "true") { Debug.Log("Player data saved succesfully"); if (logout) { Debug.Log("LOGOUT"); GameSaveUtility.Reset(); // if updating the player is called during a logout action, delete all player pref local storage canvasManager.OpenStart(); // makes sure the page when logging back in starts with the start menu and not settings } // Print Body #if (UNITY_EDITOR) Debug.Log(www.downloadHandler.text); #endif } else { Debug.Log("Player data saving failed"); Debug.Log(www.downloadHandler.text); } } } } }