DlgLoading.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using TMPro;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using UnityEngine.UI;
  6. namespace Assets
  7. {
  8. public class DlgLoading : MonoBehaviour
  9. {
  10. public TMP_InputField inputField;
  11. public Button confirmBtn;
  12. string url = "";
  13. private void Awake()
  14. {
  15. confirmBtn.onClick.AddListener(() =>
  16. {
  17. StartCoroutine("SendRequest");
  18. });
  19. }
  20. IEnumerator SendRequest()
  21. {
  22. UnityWebRequest request = UnityWebRequest.Post(url,inputField.text);
  23. yield return request.SendWebRequest();
  24. if (request.result == UnityWebRequest.Result.Success)
  25. {
  26. Debug.Log("发送完成");
  27. if (request.downloadHandler.text =="true")
  28. {
  29. }
  30. else
  31. {
  32. }
  33. }
  34. else
  35. {
  36. Debug.Log("发送失败");
  37. }
  38. StopAllCoroutines();
  39. }
  40. }
  41. }