Game Development Reference
In-Depth Information
Each will result in a simple button on screen as follows:
The controls also support using a Texture for the button content as well by providing
a texture value for the second parameter as follows:
public Texture2D myTexture;
void Start() {
myTexture = new Texture2D(125, 15);
}
void OnGUI() {
if (GUI.Button(new Rect(25, 40, 120, 30), myTexture))
{ }
}
Like the Label , the font of the text can be altered using GUIStyle or by setting the
guiText property of the GameObject. It also supports using textures in the same
way as the Label. The easiest way to look at this control is that it is a Label that
can be clicked.
The Text control
Just as there is a need to display text, there is also a need for a user to be able to enter
text, and the legacy GUI provides the following controls to do just that:
Control
Description
TextField
This is a basic text box, it supports a single line of text, no new
lines (although, if the text contains end of line characters, it will
draw the extra lines down).
TextArea
This is an extension of TextField that supports entering of
multiple lines of text; new lines will be added when the user
hits the enter key.
PasswordField
This is a variant of TextField ; however, it won't display
the value entered, it will replace each character with a
replacement character.
Note, the password itself is still stored in text form and if you are
storing users' passwords, you should encrypt/decrypt the actual
password when using it. Never store characters in plain text.
Search WWH ::




Custom Search