- Home /
why doesn't this script work
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
Answer by AVividLight · Apr 05, 2011 at 03:40 PM
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!
Answer by robertmathew · Apr 05, 2011 at 03:34 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)
{
Application.LoadLevel(LevelTovLoad);
}
}
}
here the user name is user and password is ad$$anonymous$$ when u enter the correct password and user name defined var as desiredUsername and desiredPassword you will go to levelToLoad
Answer by robertmathew · Apr 05, 2011 at 03:45 PM
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);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613120848im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i split a string[] ? 1 Answer
Javascript - Calling a random String 2 Answers
String Problem in Java Script 1 Answer
Combo Script Problem 1 Answer
How you can start the animation of an object as finished another ? 0 Answers