Hey guys, so I’m trying to use an Array to circumvent creating an actual server for login information since the program I’m making if for home use, I see no point in a PHP. Anyway so far what I have is this.
First Script:
//Strings
var firstName : String = String.Empty;
var lastName : String = String.Empty;
var desiredUser : String = String.Empty;
var desiredPass : String = String.Empty;
var confirmPass : String = String.Empty;
//Arrays
var registeredUsers : Array = [];
//Booleans
var passwordIsSame : boolean = false;
var userNameChosen : boolean = false;
var displayMessage : boolean = false;
//floats
var displayTime : float = 3;
function Start () {
}
function Update ()
{
if (displayMessage)
displayTime -= Time.deltaTime;
if(displayTime <= 0.0)
displayMessage = false;
if(desiredUser.length > 0 && desiredUser.length <= 15)
userNameChosen = true;
}
function OnGUI ()
{
//If Statements
if(displayMessage)
{
GUI.Label(new Rect (Screen.width/ 2 - 110, Screen.height/ 2 + 145, 500, 500), "Some information has not properly been filled in.");
}
//Labels
GUI.Label(new Rect(Screen.width/ 2 - 57, Screen.height/ 2 - 23, 200, 200), "Please Register an Account.");
GUI.Label(new Rect(Screen.width/ 2 - 120, Screen.height/ 2, 200, 200), "First Name:");
GUI.Label(new Rect(Screen.width/ 2 - 119, Screen.height/ 2 + 23, 200, 200), "Last Name:");
GUI.Label(new Rect(Screen.width/ 2 - 164, Screen.height/ 2 + 46, 200, 200), "Desired Username:");
GUI.Label(new Rect(Screen.width/ 2 - 161, Screen.height/ 2 + 69, 200, 200), "Desired Password:");
GUI.Label(new Rect(Screen.width/ 2 + 103, Screen.height/ 2 + 46, 200, 200), "(Limit of 15 characters.)");
GUI.Label(new Rect(Screen.width/ 2 + 103, Screen.height/ 2 + 69, 200, 200), "(Limit of 25 characters.)");
GUI.Label(new Rect(Screen.width/ 2 - 162, Screen.height/ 2 + 92, 200, 200), "Confirm Password:");
//TextFields
firstName = GUI.TextField(Rect(Screen.width/ 2 - 50, Screen.height/ 2, 150, 20), firstName, 99);
lastName = GUI.TextField(Rect(Screen.width/ 2 - 50, Screen.height/ 2 + 23, 150, 20), lastName, 99);
desiredUser = GUI.TextField(Rect(Screen.width/ 2 - 50, Screen.height/ 2 + 46, 150, 20), desiredUser, 15);
desiredPass = GUI.PasswordField(Rect(Screen.width/ 2 - 50, Screen.height/ 2 + 69, 150, 20), desiredPass, "*"[0], 25);
confirmPass = GUI.PasswordField(Rect(Screen.width/ 2 - 50, Screen.height/ 2 + 92, 150, 20), confirmPass, "*"[0], 25);
//GUI Buttons
if(GUI.Button(Rect(Screen.width/ 2 - 28, Screen.height/ 2 + 115, 100, 30), "Register"))
{
if(desiredPass.length > 0)
{
if(desiredPass == confirmPass)
{
passwordIsSame = true;
}
}
if(passwordIsSame && userNameChosen)
{
registeredUsers.Push (desiredUser);
for (var value : String in registeredUsers)
{
print(value);
}
Application.LoadLevel("Login");
}
if(!passwordIsSame || !userNameChosen)
{
displayMessage = true;
displayTime = 3.0;
}
}
}
That is used in a different scene which is for registering an account. It works too. The username you choose is pushed into the array. The thing is I want to access it in the other scene at the Login menu so it can check if the user matches what is stored in the array.
Here’s the second script:
var userToEdit : String = String.Empty;
var passToEdit : String = String.Empty;
var gameObjectArray : GameObject[] = GameObject.FindWithTag("arrayObject").GetComponent("RegistrationScript").registeredUsers;
function Start () {
}
function Update ()
{
}
function OnGUI ()
{
//Aestetics
GUI.Label(new Rect(Screen.width / 2 - 117, Screen.height / 2 + 13, 150, 20), "Password:");
GUI.Label(new Rect(Screen.width / 2 - 120, Screen.height / 2 - 10, 150, 20), "Username:");
GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 40, 500, 500), "Please Enter Your Username and Password.");
userToEdit = GUI.TextField(Rect(Screen.width / 2 - 50, Screen.height / 2 -10, 150, 20), userToEdit, 25);
passToEdit = GUI.PasswordField(Rect(Screen.width / 2 - 50, Screen.height / 2 + 13, 150, 20), passToEdit, "*"[0], 25);
//Buttons and Functionallity
if(GUI.Button(Rect(Screen.width / 2 + 30, Screen.height / 2 + 35, 100, 30), "Register"))
{
Application.LoadLevel("Registration");
}
if(GUI.Button(Rect(Screen.width / 2 -80, Screen.height / 2 + 35, 100, 30), "Login"))
{
}
}
What I want to do is at the bottom where the final button is i want to create an if statement that will ask
if(userToEdit == ‘any username stored in the database’)
Debug.Log(“This works.”)
Or something like that for confirmation so I can focus on optimizing it next.
Any help would be greatly appreciated.