Author Topic: How to replace "GUI.TextFields" for "UIInputs" in this script?  (Read 2136 times)

Unity3dNoob

  • Guest
How to replace "GUI.TextFields" for "UIInputs" in this script?
« on: September 26, 2013, 07:47:37 AM »
How to replace "GUI.TextFields" for "UIInputs" in this script?

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class database : MonoBehaviour
  5. {
  6.     public static string user = "", name = "";
  7.     private string password = "", rePass = "", message = "";
  8.  
  9.     private bool register = false;
  10.  
  11.     private void OnGUI()
  12.     {
  13.         if (message != "")
  14.             GUILayout.Box(message);
  15.  
  16.         if (register)
  17.         {
  18.             //GUILayout.Label("Email");
  19.            // email = GUILayout.TextField(email);
  20.             GUILayout.Label("Username");
  21.             user = GUILayout.TextField(user);
  22.             GUILayout.Label("Name");
  23.             name = GUILayout.TextField(name);
  24.             GUILayout.Label("password");
  25.             password = GUILayout.PasswordField(password, "*"[0]);
  26.             GUILayout.Label("Re-password");
  27.             rePass = GUILayout.PasswordField(rePass, "*"[0]);
  28.  
  29.             GUILayout.BeginHorizontal();
  30.  
  31.             if (GUILayout.Button("Back"))
  32.                 register = false;
  33.  
  34.             if (GUILayout.Button("Register"))
  35.             {
  36.                 message = "";
  37.  
  38.                 if (user == "" || name == "" || password == "")
  39.                     message += "Please enter all the fields \n";
  40.                 else
  41.                 {
  42.                     if (password == rePass)
  43.                     {
  44.                         WWWForm form = new WWWForm();
  45.                                                 //form.AddField("email", email);
  46.                         form.AddField("user", user);
  47.                         form.AddField("name", name);
  48.                         form.AddField("password", password);
  49.                         WWW w = new WWW("http:", form);
  50.                         StartCoroutine(registerFunc(w));
  51.                     }
  52.                     else
  53.                         message += "Your Password does not match \n";
  54.                 }
  55.             }
  56.  
  57.             GUILayout.EndHorizontal();
  58.         }
  59.         else
  60.         {
  61.             GUILayout.Label("User:");
  62.             user = GUILayout.TextField(user);
  63.             GUILayout.Label("Password:");
  64.             password = GUILayout.PasswordField(password, "*"[0]);
  65.  
  66.             GUILayout.BeginHorizontal();
  67.  
  68.             if (GUILayout.Button("Login"))
  69.             {
  70.                 message = "";
  71.  
  72.                 if (user == "" || password == "")
  73.                     message += "Please enter all the fields \n";
  74.                 else
  75.                 {
  76.                     WWWForm form = new WWWForm();
  77.                     form.AddField("user", user);
  78.                     form.AddField("password", password);
  79.                     WWW w = new WWW("http:", form);
  80.                     StartCoroutine(login(w));
  81.                 }
  82.             }
  83.  
  84.             if (GUILayout.Button("Register"))
  85.                 register = true;
  86.  
  87.             GUILayout.EndHorizontal();
  88.         }
  89.     }
  90.  
  91.     IEnumerator login(WWW w)
  92.     {
  93.         yield return w;
  94.         if (w.error == null)
  95.         {
  96.             if (w.text == "login-SUCCESS")
  97.             {
  98.                 print("WOOOOOOOOOOOOOOO!");
  99.             }
  100.             else
  101.                 message += w.text;
  102.         }
  103.         else
  104.         {
  105.             message += "ERROR: " + w.error + "\n";
  106.         }
  107.     }
  108.  
  109.     IEnumerator registerFunc(WWW w)
  110.     {
  111.         yield return w;
  112.         if (w.error == null)
  113.         {
  114.             message += w.text;
  115.         }
  116.         else
  117.         {
  118.             message += "ERROR: " + w.error + "\n";
  119.         }
  120.     }
  121. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to replace "GUI.TextFields" for "UIInputs" in this script?
« Reply #1 on: September 26, 2013, 03:41:04 PM »
You need to learn the basics of NGUI first before trying to do this. And there is no need to make more than one thread. http://www.tasharen.com/forum/index.php?topic=5879.msg28150#msg28150

Long story short: you are using NGUI wrong. Very wrong. NGUI's classes are components, not commands. GUI.Label etc are commands. Until you learn the difference, no one can help you.

Start with the provided examples and tutorials. Look at the input field example that comes with NGUI. Understand how it works. Only then move on with rewriting your login screen.

I will tell you this -- it will involve a lot less code than what you have now.

Unity3dNoob

  • Guest
Re: How to replace "GUI.TextFields" for "UIInputs" in this script?
« Reply #2 on: September 26, 2013, 05:27:25 PM »
I really appreciate with your help and support, i will follow your instructions, Thank you!