How to disappear a custom GUI scripted in C#

Somehow i managed to a login script it works great but i dont know to disappear it after i log in ?

You could probably disable the whole gameobject, if it doesnt have anything else…

gameObject.SetActive(false);

http://unity3d.com/learn/tutorials/modules/beginner/scripting/activating-gameobjects

or could disable the script only, similar to this:
http://unity3d.com/learn/tutorials/modules/beginner/scripting/enabling-disabling-components

or, add some boolean to the script, if its true then skip the GUI parts from the script…

Thanks let me try this , i’m new here

Nah! didn’t work for me , here is the code and can you explain how can i close it when its done ?

using UnityEngine;
using System.Collections;
public class database : MonoBehaviour
{
    public static string user = "", name = "";
    private string password = "", rePass = "", message = "";
    private bool register = false;
    private void OnGUI()
    {
        if (message != "")
            GUILayout.Box(message);
        if (register)
        {
            GUILayout.Label("Username");
            user = GUILayout.TextField(user);
            GUILayout.Label("Name");
            name = GUILayout.TextField(name);
            GUILayout.Label("password");
            password = GUILayout.PasswordField(password, "*"[0]);
            GUILayout.Label("Re-password");
            rePass = GUILayout.PasswordField(rePass, "*"[0]);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Back"))
                register = false;
            if (GUILayout.Button("Register"))
            {
                message = "";
                if (user == "" || name == "" || password == "")
                    message += "Please enter all the fields \n";
                else
                {
                    if (password == rePass)
                    {
                        WWWForm form = new WWWForm();
                        form.AddField("user", user);
                        form.AddField("name", name);
                        form.AddField("password", password);
                        WWW w = new WWW("http://f6-preview.awardspace.com/unitytutorial.com/register.php", form);
                        StartCoroutine(registerFunc(w));
                    }
                    else
                        message += "Your Password does not match \n";
                }
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            GUILayout.Label("User:");
            user = GUILayout.TextField(user);
            GUILayout.Label("Password:");
            password = GUILayout.PasswordField(password, "*"[0]);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Login"))
            {
                message = "";
                if (user == "" || password == "")
                    message += "Please enter all the fields \n";
                else
                {
                    WWWForm form = new WWWForm();
                    form.AddField("user", user);
                    form.AddField("password", password);
                    WWW w = new WWW("http://f6-preview.awardspace.com/unitytutorial.com/login.php", form);
                    StartCoroutine(login(w));
                }
            }
            if (GUILayout.Button("Register"))
                register = true;
            GUILayout.EndHorizontal();
        }
    }
    IEnumerator login(WWW w)
    {
        yield return w;
        if (w.error == null)
        {
            if (w.text == "login-SUCCESS")
            {
                print("WOOOOOOOOOOOOOOO!");
            }
            else
                message += w.text;
        }
        else
        {
            message += "ERROR: " + w.error + "\n";
        }
    }
    IEnumerator registerFunc(WWW w)
    {
        yield return w;
        if (w.error == null)
        {
            message += w.text;
        }
        else
        {
            message += "ERROR: " + w.error + "\n";
        }
    }
}

Like this ?

I looks like I only post messages to tell users to use tags :stuck_out_tongue:
Your script is really long and you should use code tags for readability.
I’m pretty sure you’ll get more answers if you do so :slight_smile:
(I might even be able to help you!)

if (w.text == "login-SUCCESS")
            {
                print("WOOOOOOOOOOOOOOO!");
            }

Currently, after a successful login all you do is print some text. Like mgear has said, you could add a bool, for example isLoggedIn, and set it to true before or after you print “WOOO!”. Then, in OnGUI() check for that bool and display only the necessary parts of your GUI.