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-31 03:34:54 +00:00
|
|
|
|
public TMPro.TextMeshProUGUI ScoreText = null;
|
|
|
|
|
public TMPro.TextMeshProUGUI ScoreOneLineText = null;
|
|
|
|
|
|
2021-01-31 00:32:29 +00:00
|
|
|
|
public InputField name;
|
2021-01-31 03:16:22 +00:00
|
|
|
|
|
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()
|
|
|
|
|
{
|
2021-01-31 03:34:54 +00:00
|
|
|
|
if (ScoreOneLineText != null){
|
|
|
|
|
Debug.Log("Score 2 ");
|
|
|
|
|
ScoreOneLineText.text = "Score: " + DataManager.Score().ToString();
|
|
|
|
|
}
|
2021-01-30 20:39:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayGame()
|
|
|
|
|
{
|
|
|
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-31 03:16:22 +00:00
|
|
|
|
public void Score()
|
2021-01-30 20:39:19 +00:00
|
|
|
|
{
|
2021-01-31 15:59:22 +00:00
|
|
|
|
StartCoroutine(GetText("https://dev.steelants.cz/GGJ2021/GeorgeJones/Server/api.php"));
|
2021-01-31 03:16:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void BackToMainMenu()
|
|
|
|
|
{
|
|
|
|
|
SceneManager.LoadScene(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RestartLevel()
|
|
|
|
|
{
|
|
|
|
|
SceneManager.LoadScene(DataManager.Level());
|
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);
|
2021-01-31 03:06:54 +00:00
|
|
|
|
form.AddField("score", DataManager.Score().ToString());
|
2021-01-31 00:32:29 +00:00
|
|
|
|
|
2021-01-31 15:59:22 +00:00
|
|
|
|
StartCoroutine(PostText("https://dev.steelants.cz/GGJ2021/GeorgeJones/Server/api.php", form));
|
2021-01-31 03:06:54 +00:00
|
|
|
|
DataManager.Level(0);
|
2021-01-31 00:32:29 +00:00
|
|
|
|
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
|
|
|
|
}
|