Im trying to make a password system that loads a level
var passwordToEdit : String = "My Password";
var LevelTovLoad : String;
private var OneTowTreeFour : String;
function OnGUI ()
{
passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);
if(passwordToEdit == OneTowTreeFour)
{
Application.LoadLevel(LevelTovLoad);
}
}
please help me iv really wanted to no this for a while now
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)
{
Application.LoadLevel(LevelTovLoad);
}
}
}
I think that you need to change you script to:
var passwordToEdit : String = "My Password";
var correctPassword : String = "OneTowTreeFour";
var levelToLoad : int = 0;
function OnGUI () {
passwordToEdit = GUI.PasswordField (Rect (10, 10, 200, 20), passwordToEdit, "*"[0], 25);
if(passwordToEdit == correctPassword) {
Application.LoadLevel(levelToLoad);
}
}
Besides rearranging your code, I changed your "LevelTovLoad" to "levelToLoad" and made it an intager instead of a string, so that you only have to put in one number. I changed the Private Variable "OneTowTreeFour" to a Public Variable called "correctPassword" and made OneTowTreeFour into the answer...
Oh, one more thing, if you want some of those really good "coder-people" to answer (or even read) your question, you should use descriptive questions, and try your best to explain your problem... Anyway, I hope I helped!
private var correctLogin : boolean;
function Update()
{
correctLogin = (username == "user" && password == "admin");
}
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)
{
Application.LoadLevel(LevelTovLoad);
}
}