- Home /
password filed and text field
in GUI.TextArea and GUI.PasswordField i am using gui.textarea as user name field and GUI.passwordField as password field .my need is i want to set a common user name and password for the user as as username-user and password-admin. it is the login screen when the player before entering the game should have to enter the user name and password i want to set the common password and username when the user enter the correct password and user name set in the script then only login button should enabled. if the user enter password- admin and username -user then only the login button should enabled other wise it should remain login button as disable condition.i want to set user name - user and password- admin as common for all user. with out entering the this user name and password the login button should not enabled
Answer by Scribe · Mar 25, 2011 at 04:59 PM
var desiredUsername = "user"; var stringToEdit = ""; var desiredPassword = "admin"; var passwordToEdit = "";
function OnGUI () { // Make a multiline text area that modifies stringToEdit. GUI.Label(Rect (10, 10, 60, 20), "Username: "); GUI.Label(Rect (10, 35, 60, 20), "Password: ");
stringToEdit = GUI.TextField (Rect (75, 10, 200, 20), stringToEdit, 200);
passwordToEdit = GUI.PasswordField (Rect (75, 35, 200, 20), passwordToEdit, "*"[0], 25);
if(stringToEdit == desiredUsername){
if(passwordToEdit == desiredPassword){
GUI.Button(Rect(75, 60, 50, 20),"Login");
}
}
}
put this on your camera, you can change the password and username by changing the desired variables
hope this helps
Scribe
Answer by Statement · Mar 25, 2011 at 05:02 PM
var btnColorOn : Color = Color(1.0f, 1.0f, 1.0f, 1.0f); var btnColorOff : Color = Color(0.4f, 0.4f, 0.4f, 1.0f);
private var btnColor = btnColorOff; private var username : String = String.Empty; private var password : String = String.Empty; private var correctLogin : boolean;
function Update() { correctLogin = (username == "user" && password == "admin");
var speed = Time.deltaTime * 4;
var targetColor = correctLogin ? btnColorOn : btnColorOff;
btnColor.r = Mathf.MoveTowards(btnColor.r, targetColor.r, speed);
btnColor.g = Mathf.MoveTowards(btnColor.g, targetColor.g, speed);
btnColor.b = Mathf.MoveTowards(btnColor.b, targetColor.b, speed);
btnColor.a = Mathf.MoveTowards(btnColor.a, targetColor.a, speed);
}
function OnGUI() { var windowRect : Rect; windowRect.x = Screen.width / 2 - 100; windowRect.y = Screen.height / 2 - 50; windowRect.width = 200; windowRect.height = 100;
GUI.Window(0, windowRect, OnWindowGUI, "Authentication");
}
function OnWindowGUI() { username = GUILayout.TextField(username); password = GUILayout.PasswordField(password, '*'[0]); GUI.color = btnColor; if (GUILayout.Button("Login") && correctLogin) { // Add your login code here... enabled = false; } GUI.color = Color.white; }
Your answer
Follow this Question
Related Questions
gui text and password field 1 Answer
TextFields Android issue: switching between different fields it copies the string 0 Answers
iOS Keyboard makes performance suffer 3 Answers
Can't Input when focus a text field 2 Answers
android textfield problem 1 Answer