Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
1,324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. string loginCode="http://localhost/unity_db/login.php";
  2. string registerCode="http://localhost/unity_db/register.php";
  3.  
  4. public string username="";
  5. public string password="";
  6. public string output="";
  7.  
  8.  
  9. void Start () {
  10. Debug.Log("print");
  11. }
  12. // Update is called once per frame
  13. void Update () {
  14. }
  15.  
  16. void OnGUI()
  17. {
  18. GUI.Window (0, new Rect (Screen.width/4,Screen.height/4,Screen.width/2,Screen.height/2-5), LoginWindow, "Login");
  19.  
  20. }
  21. void LoginWindow(int windowID)
  22. {
  23. GUI.Label (new Rect (140, 40, 130, 100), "Enter the Username");
  24. username = GUI.TextField (new Rect (25, 60, 375, 30), username);
  25. GUI.Label (new Rect (140, 92, 130, 100), "Enter the Password");
  26. password = GUI.TextField(new Rect (25, 115, 375, 30), password);
  27. if (GUI.Button (new Rect (29, 160, 175, 50), "Login"))
  28. StartCoroutine(handleLogin(username,password));
  29. GUI.Label (new Rect (55, 222, 250, 100),output);
  30. if(GUI.Button (new Rect (225, 160, 175, 50), "Register"))
  31. StartCoroutine(handleRegister(username,password));
  32. }
  33.  
  34. IEnumerator handleLogin(string user,string pass)
  35. {
  36. /*if (username == "Achu" && password == "achu123") {
  37. Debug.Log (username + password);
  38. } else {
  39. Debug.Log ("error");
  40. }*/
  41.  
  42. string login_url = loginCode + "?username=" + user + "&password=" + pass;
  43. WWW logindata = new WWW (login_url);
  44. yield return logindata;
  45. if (logindata.text == "right") {
  46. output="login successful";
  47.  
  48. } else {
  49. output="invalid user pass";
  50. }
  51.  
  52.  
  53. }
  54. IEnumerator handleRegister(string user,string pass)
  55. {
  56.  
  57. string register_url = registerCode + "?username=" + user + "&password=" + pass;
  58. WWW registerdata = new WWW (register_url);
  59. yield return registerdata;
  60. if(registerdata.text=="registered")
  61. {
  62. output="registration successful";
  63. }
  64. else{
  65. output="registration failed pass";
  66. }
  67.  
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement