Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Menu : MonoBehaviour
- {
- string loginURL = "localhost";
- string username = "";
- string password = "";
- string label = "";
- void OnGUI()
- {
- GUI.Window(0, new Rect(Screen.width / 6, Screen.height / 4, 220, 260), LoginWindow, "Login");
- }
- void LoginWindow(int OnGUI)
- {
- GUI.Label(new Rect(10,30,200,30), "Username");
- username = GUI.TextField(new Rect(10,60,200,30), username);
- GUI.Label(new Rect(10,100,200,30), "Password");
- password = GUI.TextField(new Rect(10,130,200,30), password, '*');
- if (GUI.Button(new Rect(10,170,200,30), "Login"))
- {
- StartCoroutine(HandleLogin(username, password));
- Debug.Log("connect button pressed");
- }
- GUI.Label (new Rect(10,200,200,60), label);
- }
- IEnumerator HandleLogin(string username, string password)
- {
- label = "Checking username and password.";
- string loginURL = this.loginURL + "?UserAccountName=" + username + "&UserAccountPassword=" + password;
- WWW loginReader = new WWW(loginURL);
- yield return loginReader;
- Debug.Log (username);
- if(loginReader.error != null)
- {
- Debug.Log ("error1");
- label = "Error connecting to database server.";
- }
- else
- {
- if (loginReader.text == "Success")
- {
- label = "Successfully logged in.";
- Debug.Log ("yay fucking finally");
- }
- else
- {
- label = "Invalid username or password.";
- Debug.Log ("Connected, but wrong user/password");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement