Advertisement
kmccmk9

Unity C#

Jul 19th, 2012
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Login : MonoBehaviour {
  5.  
  6.     public Texture LoginBackground;
  7.     public Texture2D stylebackground;
  8.     public GUIStyle LoginStyle;
  9.     public GUIStyle LoginTextBox;
  10.     public GUIStyle LoginButton;
  11.     public string Username;
  12.     public string Password;
  13.     public float transparent;
  14.     private string url;
  15.     public WWW w;
  16.     public WWWForm loginform;
  17.     // Use this for initialization
  18.     void Start () {
  19.         LoginStyle.fontSize = 72;
  20.         LoginStyle.alignment = TextAnchor.MiddleCenter;
  21.         LoginTextBox.fontSize = 20;
  22.         LoginTextBox.alignment = TextAnchor.MiddleCenter;
  23.         LoginTextBox.normal.background = stylebackground;
  24.         LoginButton.fontSize = 30;
  25.         LoginButton.alignment = TextAnchor.MiddleCenter;
  26.         url = "http://redlightlife.tk/scripts/checklogin.php";
  27.         loginform = new WWWForm();
  28.     }
  29.    
  30.     // Update is called once per frame
  31.     void Update () {
  32.    
  33.     }
  34.    
  35.     void OnGUI() {
  36.         GUI.backgroundColor = Color.black;
  37.         GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),LoginBackground,ScaleMode.StretchToFill, false, 0.0f);
  38.         GUI.Label(new Rect(Screen.width/2-250,Screen.height/2-250,500,250),"Username:", LoginStyle);
  39.         Username = GUI.TextField(new Rect(Screen.width/2-250,Screen.height/2-80,500,50), Username, 10, LoginTextBox);
  40.         GUI.Label(new Rect(Screen.width/2-250,Screen.height/2-50,500,250),"Password:", LoginStyle);
  41.         Password = GUI.TextField(new Rect(Screen.width/2-250,Screen.height/2+120,500,50), Password, 10, LoginTextBox);
  42.         if (GUI.Button(new Rect(Screen.width/2-150,Screen.height/2+200,300,50),"Login:", LoginButton))
  43.         {
  44.             //CheckLogin();
  45.             StartCoroutine(CheckLogin());
  46.         }
  47.     }
  48.    
  49.     IEnumerator CheckLogin()
  50.     {
  51.             loginform.AddField("username", Username);
  52.             loginform.AddField("password", Password);
  53.             w = new WWW(url,loginform);
  54.             yield return w;
  55.             Debug.Log("Downloaded");
  56.             if (w.error != null)
  57.             {
  58.             print(w.error);
  59.             }
  60.             if (w.error == null)
  61.             {
  62.             print("Fetching Data");
  63.             print("Uwsername=" + Username);
  64.             print ("Passowrd=" + Password);
  65.             string formText = w.text;
  66.             w.Dispose();
  67.             print(formText);
  68.             }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement