hello im making a project for school. and it will be an mobile app… im working for 3 days to make a UI login system but the problem is i dont know how to link the UI textbox area to the script for checking if the username and the password is correct… the code is here :
var Username = "";
var Password = "";
var OwnerUser = "user";
var OwnerPass = "pass";
var userCORRECT = false;
var passCORRECT = false;
var userArea = gameObject;
var passArea = gameObject;
function CheckUser()
{
if(userCORRECT == OwnerUser)
{
userCORRECT = true;
} else {
userCORRECT = false;
}
}
function CheckPass()
{
if(passCORRECT == OwnerPass)
{
passCORRECT = true;
} else {
passCORRECT = false;
}
}
function Update()
{
// here needs function for if you press on the button and if the user and pass is correct it will load a new scene.
if(userCORRECT == true)
{
if(passCORRECT == true)
{
Application.LoadLevel("A_Level");
}
}
}
function AreaUI()
{
// here needs a function for if you type in the UI inputField that if you type the correct username and pass it will automaticly set it to true. if its not false.
}
Make a public function (in UnityScript that’s a normal function) with the parameter for a string.
function OnSubmit(username) {// Like so.
//What to do with the value from input field
}
Then in the editor, go to the Username field that I assume you’ve created and there should be a End Edit list.
All you do is simply point the script to the object the script contains and it will let you select the OnSubmit function.
You can also point it to the On Value Change list, which will continuely call that function until the user is done editing the field.
You can also do it this way: (This is C#)
private InputField usernameInputField =null;
private Button loginButton = null;
private void Start() {
// Add listener to catch the submit (when set login button is pressed)
var Username = "";
var Password = "";
var OwnerUser = "user";
var OwnerPass = "pass";
var userCORRECT = false;
var passCORRECT = false;
var userArea = gameObject;
var passArea = gameObject;
public function OnSubmit(Username)
{
}
function CheckUser1()
{
if(OwnerUser == Username)
{
if(Username == userCORRECT)
{
if(userCORRECT == true)
{
userCORRECT = true;
} else {
userCORRECT = false;
}
}
}
}
function CheckPass()
{
if(passCORRECT == OwnerPass)
{
passCORRECT = true;
} else {
passCORRECT = false;
}
}
function Update()
{
// here needs function for if you press on the if the user and pass is correct and loads the level.
if(userCORRECT == true)
{
if(passCORRECT == true)
{
Application.LoadLevel("A_Level");
}
}
}
function AreaUI()
{
// here needs a function for if you type in the UI inputField that if you type the correct username and pass it will automaticly set it to true. if its not false.
}