frostyfire

login

Aug 21st, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 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 Login : MonoBehaviour
  8. {
  9. public InputField nameField;
  10. public InputField passwordField;
  11.  
  12. public Button submitButton;
  13.  
  14. public void CallLogin()
  15. {
  16. StartCoroutine(LoginPlayer());
  17. }
  18.  
  19. IEnumerator LoginPlayer()
  20. {
  21. WWWForm form = new WWWForm();
  22. form.AddField("name", nameField.text);
  23. form.AddField("password", passwordField.text);
  24. UnityWebRequest www = UnityWebRequest.Post("http://localhost/sqlconnect/login.php", form);
  25. yield return www.SendWebRequest();
  26.  
  27. if (www.downloadHandler.text.Split('\t')[0] == "0")
  28. {
  29. DBManager.username = nameField.text;
  30. DBManager.score = int.Parse(www.downloadHandler.text.Split('\t')[1]);
  31. DBManager.house = www.downloadHandler.text.Split('\t')[2];
  32. UnityEngine.SceneManagement.SceneManager.LoadScene(0);
  33. }
  34.  
  35. else
  36. {
  37. Debug.Log("User login failed. Error #" + www.downloadHandler.text);
  38. }
  39. }
  40. public void VerifyInputs()
  41. {
  42. submitButton.interactable = (nameField.text.Length >= 8 && passwordField.text.Length >= 8);
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment