- Home /
How to Get a Login Function to Work Locally?
So I am making this program for my Dad to use at work so he can take Inventory on Items and a few other things. What I want to do is create a Login system that doesn't use network functionality it just checks if the fields are correct and loads the program. Currently what I have seems to work for getting the correct Login but I cannot get it to detect an incorrect Login. My current Script looks like this. var userToEdit : String; var passwordToEdit : String; var customSkin : GUISkin; var correctLogin : boolean = false;
function Start () {
}
function Update ()
{
if(userToEdit == "User" && passwordToEdit == "password")
{
correctLogin = true;
}
else
{
correctLogin = false;
}
}
function OnGUI ()
{
GUI.skin = customSkin;
userToEdit = GUI.TextField(Rect (Screen.width/ 2 - 50,Screen.height/2,200,20), userToEdit, 25);
passwordToEdit = GUI.PasswordField(Rect (Screen.width/2 - 50,Screen.height/2 + 25,200,20), passwordToEdit, "*"[0], 25);
if(GUILayout.Button("Login", "button") && correctLogin == true)
{
Debug.Log("This Button Works!");
}
else
{
Debug.Log("Login Failure");
}
}
Originally there wasn't a boolean but I added it to see if it would work better to no avail. What I think is the issue is that the Button I create isn't a permanent object and I cannot reference it outside of that one line of code. How can I make it so if the User and Password are incorrect and I click the Login button it will display "Incorrect Login" in the Debug Log? Any help will be very much appreciated :)
Answer by Maerig · May 09, 2014 at 02:43 AM
if(GUILayout.Button("Login", "button"))
{
if(correctLogin)
{
Debug.Log("This Button Works!");
}
else
{
Debug.Log("Login Failure");
}
}
I feel really stupid now, but thank you very much for the help xD I guess it serves me right for staying up so late trying to do this!
Your answer
Follow this Question
Related Questions
How do I change the text of a gui image text 1 Answer
NGUI Repeat button In JavaScript problem 1 Answer
GuiTexture Width Change 1 Answer
Setting Scroll View Width GUILayout 1 Answer
facebook with unity problem 0 Answers