Z_END_GAME.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using System.Linq;
  6. public class Z_END_GAME : MonoBehaviour
  7. {
  8. public GameObject serverManager;
  9. public GameObject gameFinished;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. }
  18. public void EndGame()
  19. {
  20. string gameNumber = serverManager.GetComponent<CurrentGameConnect>().GetGameNumber();
  21. StartCoroutine(EndGame(gameNumber));
  22. }
  23. public IEnumerator EndGame(string gameNumber)
  24. {
  25. // CHANGE THE OBJECT COLOR
  26. string serverUrl = "https://smarthubs.media.tuwien.ac.at/api/close_game/";
  27. WWWForm form = new WWWForm();
  28. form.AddField("game", gameNumber);
  29. using (UnityWebRequest www = UnityWebRequest.Post(serverUrl, form)){
  30. yield return www.SendWebRequest();
  31. if (www.result != UnityWebRequest.Result.Success)
  32. {
  33. Debug.Log(www.error);
  34. //errorPanel.SetActive(true);
  35. }
  36. else
  37. {
  38. gameFinished.SetActive(true);
  39. }
  40. }
  41. }
  42. }