- Home /
Unity login and password help
Hey guys!
In my game, i have a username and password. This is not connected to any website or server. but, i have a certain password and username when players buy the game, they see on like a piece of paper. So when they enter it correctly, it goes to my main menu scene. but if the messed up the password or username, it stays on the same scene. Help??
Here is the login script.
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 * 0;
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, "Login");
}
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; }
Please format your code. If you don't know how watch the tutorial video on the right
Question: Can you possibly read the code in your question (actually look at it)?
Answer: No
Why?
Whatch the tutorial video on the right
Your answer
Follow this Question
Related Questions
[Meta] How can I change my username? 2 Answers
How do you make a password script in c#? 0 Answers
How can i create a network mutliplayer login? 0 Answers
Unity Networking Question [Username/Pass] 0 Answers
Facebook log in with email and password 0 Answers