Score Fetch
This commit is contained in:
@@ -2,13 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Networking;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
|
||||
public class MainMenu : MonoBehaviour
|
||||
{
|
||||
public TMPro.TextMeshProUGUI ScoreText;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -24,7 +27,8 @@ public class MainMenu : MonoBehaviour
|
||||
|
||||
public void Credits()
|
||||
{
|
||||
|
||||
StartCoroutine(GetText("dev.steelants.cz/vasek/GGJ2021/GeorgeJones/Server/api.php"));
|
||||
ScoreText.text = "test";
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
@@ -32,4 +36,20 @@ public class MainMenu : MonoBehaviour
|
||||
Debug.Log("Quit");
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
IEnumerator GetText(string uri) {
|
||||
UnityWebRequest www = UnityWebRequest.Get(uri);
|
||||
yield return www.SendWebRequest();
|
||||
|
||||
if(www.isNetworkError || www.isHttpError) {
|
||||
Debug.Log(www.error);
|
||||
}
|
||||
else {
|
||||
// Show results as text
|
||||
Debug.Log(www.downloadHandler.text);
|
||||
ScoreText.text = www.downloadHandler.text;
|
||||
// Or retrieve results as binary data
|
||||
byte[] results = www.downloadHandler.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user