Advertisement
Guest User

Untitled

a guest
Apr 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5. using System;
  6. using System.IO;
  7. using System.Runtime.Serialization;
  8.  
  9.  
  10.  
  11.  
  12.  
  13. public class LoginDB : MonoBehaviour {
  14.  
  15.     public static string user = "";
  16.     private string password = "", id = "";
  17.     public InputField loginInput;
  18.     public InputField passInput;
  19.     public Text text;
  20.  
  21.    
  22.  
  23.     public void toReg()
  24.     {
  25.         Application.LoadLevel("Regist");
  26.     }
  27.  
  28.  
  29.  
  30.     [System.Serializable]
  31.     public class users
  32.     {
  33.         public string id;
  34.         public string name;
  35.         public string klass;
  36.         public string gold;
  37.         public string exp;
  38.         public string level;
  39.     }
  40.  
  41.     public void Login()
  42.     {
  43.         //message = "";
  44.         user = loginInput.text.ToString ();
  45.         password = passInput.text.ToString ();
  46.  
  47.         if (user == "" || password == "")
  48.             text.text = "Please enter all the fields \n";
  49.         else
  50.         {
  51.             WWWForm form = new WWWForm();
  52.             form.AddField("email", user);
  53.             form.AddField("password", password);
  54.             WWW www = new WWW("http://uo.cx.ua/api/auth/login", form);
  55.             StartCoroutine(login(www));
  56.  
  57.         }
  58.  
  59.         }
  60.     IEnumerator login(WWW www)
  61.     {
  62.         yield return www;
  63.         if (www.error != null)
  64.         {
  65.             Debug.Log ("error " + www.error);
  66.  
  67.             }
  68.         else
  69.         {
  70.             string json = www.text;
  71.             users us = JsonUtility.FromJson<users> (json);
  72.             Debug.Log (json);
  73.  
  74.         }
  75.     }
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement