Form with New UI System

Hello guys i want a make a logn system with UI System how i can make this?

Watch the tutorial videos. They basically cover everything to make a simple form like login. The tutorial videos are linked off the beta download page.

what video number?

  1. UI Canvas

  2. UI Rect Transform

  3. UI Button

  4. UI Image

  5. UI Text

  6. UI Events and Event Triggers

  7. UI Slider

  8. UI Transitions

  9. UI Scroll Rect

  10. UI Scrollbar

  11. UI Mask

  12. The New UI

2 Likes

I would advise watching up through number 5 for the basics, though all of them are useful. Otherwise, ask yourself - what is a login form made up of? At the very basics, two text boxes and a ‘login’ button.

I have a feeling where he’s mainly running into trouble is using the username and password to actually login to a website; if so, the issues are not with understanding the UI system at all, but rather with the networking aspect of the task. (Incidentally, I tried and failed at that a while back using the WWW class, and would be interested in seeing how it’s done)

this is y script but i need add UI System

using UnityEngine;
using System.Collections;

public class Connection : MonoBehaviour
{
    public string username = "";
    public string password= "";
    public string repassword= "";
    public string email= "";
    public string message= "";
    public GUISkin hdskin;
    public int HofBox = 25;   
    public string loguser= "";
   
    private string logpass= "";
    private string logmessage= "";
    private int generatednumber = 0;
    private int numberinput;
   
    private bool islogin = true;
    private bool isregister = false;
   
    private string CurrentMenu = "Menu";
   
    void  OnGUI ()
    {
        if(CurrentMenu == "Menu")
        {
            GUI.skin = hdskin;
            if(islogin == false && isregister == true)
            {
                GUI.Box( new Rect(Screen.width /2-250,20,500,480),"");
                GUI.Label( new Rect(Screen.width /2-100,30,200,50),"Please fill out the fields");
                GUI.Label( new Rect(Screen.width /2-230, 130,200,50),"Username:");
                username = GUI.TextField( new Rect(Screen.width /2-20,130,200,HofBox),username,45);
                GUI.Label( new Rect(Screen.width /2-230,190,200,50),"Password:");
                password = GUI.PasswordField( new Rect(Screen.width /2-20,190,200,HofBox),password,"*"[0],45);
                GUI.Label( new Rect(Screen.width /2-230,250,200,50),"Re-Enter pass:");
                repassword = GUI.PasswordField( new Rect(Screen.width /2-20,250,200,HofBox),repassword,"*"[0],45);
                GUI.Label( new Rect(Screen.width /2-230,310,200,50),"Email:");
                email = GUI.TextField( new Rect(Screen.width /2-20,310,200,HofBox),email,45);
                GUI.Label( new Rect(Screen.width /2-230,360,150,50),"Please verify:");
                GUI.Label( new Rect(Screen.width /2-80,360,100,HofBox),generatednumber.ToString());
                numberinput = int.Parse(GUI.TextField( new Rect(Screen.width /2+80,360,100,HofBox),numberinput.ToString()));
                if(GUI.Button( new Rect(Screen.width /2-230,420,200,HofBox),"Register!"))
                {
                    message = "";   
                    if(username == "" || email == "" || password == "" || numberinput == 0){
                        message += "Please fill in the empty fields. \n";
                    }else{
                        if(password == repassword){
                            if(numberinput == generatednumber){
                                StartCoroutine("doRegister");
                            }else{
                                message += "The number you inputed is not the same number.";
                            }
                           
                        }else{
                            message += "The passwords do not match. \n";
                        }
                    }   
                }
                if(GUI.Button( new Rect(Screen.width /2-20,420,200,HofBox),"Return to login"))
                {
                    islogin = true;
                    isregister = false;
                    username = ""; //cleaning our variables
                    password = "";
                    repassword = "";
                    email = "";
                    numberinput = 0;
                    message = "";
                    loguser = "";
                    logpass = "";
                    logmessage = "";
                }
                if(message != "")
                {
                    GUI.Label( new Rect(Screen.width /2-230,460,460,50), message);
                }}
            else if(islogin == true && isregister == false)
            {
                StartCoroutine (ServerRefresh ());
               
                GUI.Box( new Rect(Screen.width /2-250,20,500,450),"");
               
                if(MasterServer.PollHostList().Length != 0)
                {
                    HostData[] data = MasterServer.PollHostList();
                    foreach(HostData c in data)
                    {
                        GUILayout.BeginArea(new Rect(Screen.width /2-65,30,200,50));
                        GUILayout.Label(c.gameName + " " + (c.connectedPlayers - 1) + "/" + c.playerLimit);
                        GUILayout.EndArea();
                    }

                    //Login Button ///////////////////////////////////////////////////////////////////////////////////////
                    if(GUI.Button( new Rect(Screen.width /2-230,330,200,HofBox),"Login")){
                        if(loguser == "" || logpass == ""){
                            logmessage += "Please enter the necessary data! \n";
                        } else{
                            logmessage = "";
                            StartCoroutine("doLogin");
                        }
                    }
                }
                else
                {
                    GUILayout.BeginArea(new Rect(Screen.width /2-65,30,200,50));
                    GUI.color = Color.red;
                    GUILayout.Label("Server Offline");
                    GUI.color = Color.white;
                    GUILayout.EndArea();
                }
               
                GUI.Label( new Rect(Screen.width /2-230, 130,200,50),"Username:");
                loguser = GUI.TextField( new Rect(Screen.width /2-20,130,200,HofBox),loguser,45);
                GUI.Label( new Rect(Screen.width /2-230,230,200,50),"Password:");
                logpass = GUI.PasswordField( new Rect(Screen.width /2-20,230,200,HofBox),logpass,"*"[0],45);




                if(GUI.Button( new Rect(Screen.width /2-20,330,200,HofBox),"Register"))
                {
                    islogin = false;
                    isregister = true;
                    generatednumber=Random.Range(1000,99999);
                    username = ""; //cleaning our variables
                    password = "";
                    repassword = "";
                    email = "";
                    numberinput = 0;
                    message = "";
                    loguser = "";
                    logpass = "";
                    logmessage = "";
                }
                if(logmessage != "")
                {
                    GUI.Label( new Rect(Screen.width /2-230,360,460,50),logmessage);
                }
            }
        }//CurrentMenu = Menu
    }//OnGui
   
    public void OnConnectedToServer()
    {
        islogin = false;
        isregister = false;
        networkView.RPC("Login",RPCMode.All,loguser,Network.player);
               
        Application.LoadLevel (2);
    }
   
    private void OnDisconnectedFromServer()
    {
        CurrentMenu = "Menu";
    }
   
    private IEnumerator doRegister()
    {
        WWWForm form = new WWWForm();
        form.AddField("Username" , username);
        form.AddField("Password" , password);
        form.AddField("Email" , email);           
        var w = new WWW(Info.webSite + "/Register.php", form);           
        yield return w;
        if(w.error == null){
            message += w.text;
            StopCoroutine("doRegister");
        }else{
            message += "Error : " + w.error + "\n";
        }
    }
    private IEnumerator doLogin()
    {
        WWWForm logform = new WWWForm();
        logform.AddField("Username" , loguser);
        logform.AddField("Password" , logpass);
        var logw = new WWW(Info.webSite + "/Login.php", logform);
        yield return logw;
        if(logw.error == null){
            logmessage += logw.text;

            StopCoroutine("doLogin");
        }else{
            logmessage +="Error : " + logw.error + "\n";   
        }
        if(logmessage == "Login success! Please wait while the game loads..."){
            Network.Connect("avct.sytes.net", 8632);
        }
    }
   
    private IEnumerator ServerRefresh()
    {
        yield return new WaitForSeconds(3);
        MasterServer.RequestHostList("MMOFPS");
    }

    [RPC]
    public void Login(string loguser,NetworkPlayer player)
    {
        Info.Owner = loguser;
    }
}

Alright, so my guess was incorrect. So, watch the tutorials. They lay it out pretty clearly. If you have more specific questions about the tutorials, we’ll be happy to help.

already see al tutorials and no one have form

The tutorial isn’t going to give you the exact thing you need. You’re a human being with a functioning brain. You’re gonna have to use it.

Or, in other words: What specifically is missing from the tutorials that you don’t understand how to do?

Forms are not the UI component. Your text fields and buttons are. To integrate them with code, make sure to include

using UnityEngine.UI;

Tutorials aren't custom tailored to entire pages - they tell you how to do each part. It is up to you to put it all together, just like you did with the old GUI in that script.

Foundation includes a Login system. It has Signup, SignIn, Password Reset... the works.

I am converting it to uGUI as we speak.

how i can make text field with ui?

Create InputField from create menu like Button.

can u show me like picture? dont understand

1745057--110239--Untitled.png
trolling++?

1 Like

ho shit i dont see this buttons lol… thanks u

That’s strange. Don’t they open those menus many times in the tutorial?

sorry but i dont see this on the tutorials