Game Development Reference
In-Depth Information
To start, create a new script called IntermediateGUI in your project (the full sample
can be found in the project available with this topic in the code download) and
replace its contents with the following:
using UnityEngine;
[ExecuteInEditMode]
public class IntermediateGUI : MonoBehaviour {
public string username = "Enter username";
public string password = "Enter password";
private bool passwordInError = false;
private string passwordErrorMessage =
"<color=red>Password too short</color>";
}
This gives a basic class with some of the parameters you might expect in a logon
or registration form.
To this we'll add a simple function to validate the password entered to ensure it
meets our stringent security policy:
void CheckUserPasswordAndRegister()
{
if (password.Length < 6)
{
//If the password is not long enough, mark it in error
//and focus on the password field
passwordInError = true;
GUI.FocusControl("PasswordField");
} else
{
passwordInError = false;
GUI.FocusControl("");
//Register User
}
}
With that in place, now we can add our GUI controls:
void OnGUI() {
//A tidy group for our fields and a box to decorate it
GUI.BeginGroup(new Rect(Screen.width / 2 - 75,
Screen.height / 2 - 80, 150,160));
GUI.Box(new Rect(0,0,150,160), "User registration form");
 
Search WWH ::




Custom Search