GlobalGameJam-2021/Assets/Scripts/MainMenu.cs

75 lines
1.8 KiB
C#
Raw Normal View History

2021-01-30 20:39:19 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
2021-01-30 22:32:01 +00:00
using UnityEngine.Networking;
2021-01-31 00:32:29 +00:00
using UnityEngine.UI ;
2021-01-30 22:32:01 +00:00
using System.Collections;
using TMPro;
2021-01-30 20:39:19 +00:00
public class MainMenu : MonoBehaviour
{
2021-01-30 22:32:01 +00:00
public TMPro.TextMeshProUGUI ScoreText;
2021-01-31 00:32:29 +00:00
public InputField name;
2021-01-30 20:39:19 +00:00
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void PlayGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
public void Credits()
{
StartCoroutine(GetText("dev.steelants.cz/GGJ2021/GeorgeJones/Server/api.php"));
2021-01-30 22:32:01 +00:00
ScoreText.text = "test";
2021-01-30 20:39:19 +00:00
}
public void QuitGame()
{
Debug.Log("Quit");
Application.Quit();
}
2021-01-30 22:32:01 +00:00
2021-01-31 00:32:29 +00:00
public void ScoreSubmit()
{
WWWForm form = new WWWForm();
form.AddField("name", name.text);
form.AddField("score", 20);
StartCoroutine(PostText("dev.steelants.cz/vasek/GGJ2021/GeorgeJones/Server/api.php", form));
SceneManager.LoadScene(0);
}
2021-01-30 22:32:01 +00:00
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;
}
}
2021-01-31 00:32:29 +00:00
IEnumerator PostText(string uri, WWWForm data) {
UnityWebRequest www = UnityWebRequest.Post(uri, data);
yield return www.SendWebRequest();
if(www.isNetworkError || www.isHttpError) {
Debug.Log(www.error);
}
}
2021-01-30 20:39:19 +00:00
}