frostyfire

game

Aug 21st, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Networking;
  6.  
  7. public class Game : MonoBehaviour
  8. {
  9. public Text playerDisplay;
  10. public Text scoreDisplay;
  11.  
  12.  
  13. void Awake()
  14. {
  15. if (DBManager.username == null)
  16. {
  17. UnityEngine.SceneManagement.SceneManager.LoadScene(0);
  18. }
  19. playerDisplay.text = "Player: " + DBManager.username;
  20. scoreDisplay.text = "Score: " + DBManager.score;
  21. }
  22.  
  23. public void CallSaveData()
  24. {
  25. StartCoroutine(SavePlayerData());
  26. }
  27.  
  28. IEnumerator SavePlayerData()
  29. {
  30. WWWForm form = new WWWForm();
  31. form.AddField("name", DBManager.username);
  32. form.AddField("score", DBManager.score);
  33.  
  34. UnityWebRequest www = UnityWebRequest.Post("http://localhost/sqlconnect/savedata.php", form);
  35. yield return www.SendWebRequest();
  36. if (www.downloadHandler.text == "0")
  37. {
  38. Debug.Log("Game Saved.");
  39. }
  40. else
  41. {
  42. Debug.Log("Save failed. Error #" + www.downloadHandler.text);
  43. }
  44.  
  45. DBManager.LogOut();
  46. UnityEngine.SceneManagement.SceneManager.LoadScene(0);
  47. }
  48.  
  49. public void IncreaseScore()
  50. {
  51. DBManager.score++;
  52. scoreDisplay.text = "Score: " + DBManager.score;
  53. }
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment