Improved scoreboardManager error messages

This commit is contained in:
2022-04-24 14:28:45 +02:00
parent 1c8d428f08
commit b71dcdf961

View File

@@ -71,12 +71,14 @@ public class ScoreboardManager : MonoBehaviour
if (www.result != UnityWebRequest.Result.Success) if (www.result != UnityWebRequest.Result.Success)
{ {
Debug.Log(www.error); Debug.Log(www.error);
btnSubmit.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = "Error :(";
} }
else else
{ {
Debug.Log("Score submitted"); Debug.Log("Score submitted");
btnSubmit.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = "Submitted!"; btnSubmit.GetComponentInChildren<TMPro.TextMeshProUGUI>().text = "Submitted!";
submitted = true; submitted = true;
StartCoroutine(GetScores());
} }
} }
} }
@@ -88,22 +90,24 @@ public class ScoreboardManager : MonoBehaviour
// Request and wait for the desired page. // Request and wait for the desired page.
yield return webRequest.SendWebRequest(); yield return webRequest.SendWebRequest();
globalNames.text = "";
globalScores.text = "";
switch (webRequest.result) switch (webRequest.result)
{ {
case UnityWebRequest.Result.ConnectionError: case UnityWebRequest.Result.ConnectionError:
case UnityWebRequest.Result.DataProcessingError: case UnityWebRequest.Result.DataProcessingError:
Debug.LogError("Error: " + webRequest.error); Debug.LogError("Error: " + webRequest.error);
globalNames.text = "Error: " + webRequest.error;
break; break;
case UnityWebRequest.Result.ProtocolError: case UnityWebRequest.Result.ProtocolError:
Debug.LogError("HTTP Error: " + webRequest.error); Debug.LogError("HTTP Error: " + webRequest.error);
globalNames.text = "Error: " + webRequest.error;
break; break;
case UnityWebRequest.Result.Success: case UnityWebRequest.Result.Success:
Debug.Log("Received: " + webRequest.downloadHandler.text); Debug.Log("Received: " + webRequest.downloadHandler.text);
Scores scores = JsonUtility.FromJson<Scores>("{\"scores\":" + webRequest.downloadHandler.text + "}"); Scores scores = JsonUtility.FromJson<Scores>("{\"scores\":" + webRequest.downloadHandler.text + "}");
globalNames.text = "";
globalScores.text = "";
foreach (Score score in scores.scores) foreach (Score score in scores.scores)
{ {
globalNames.text += score.username + "\n"; globalNames.text += score.username + "\n";