Home » ASP.NET » Unity3D based text entry --button

Unity3D based text entry --button

Button is a common control of the GUI system in Unity3D, and its function prototype is as follows:

staticfunction Button (position:, Rect, text:, string) : bool; 
Staticfunction Button (position:, Rect, image:, Texture) : bool;
Staticfunction Button (position:, Rect, content:, GUIContent) : bool;
Staticfunction, Button (position:, Rect, text:, string, style:, GUIStyle) : bool;
Staticfunction, Button (position:, Rect, image:, Texture, style:, GUIStyle) : bool;
Staticfunction, Button (position:, Rect, content:, GUIContent, style:, GUIStyle) : bool;

Parameter Description:

Position: Rect - the location of the rectangle on the screen (x coordinates, y coordinates, width, height).

Text: String - display the text content.

Image: Texture - the texture (picture) displayed.

Content: GUIContent - text, pictures, and information hints displayed on the tag.

Style: GUIStyle - the style used, if not used, then the label style is the current GUISkin skin

The button has three basic states: click status, hit state, and click status. In general, the button on the game interface monitors only the two states of "not clicked" and "after clicking".

There are two styles of button display: the ordinary button and the picture button. The ordinary button is the button shown by the system default, and the picture button can set the background pattern of the button.

Here's an example of the actual simple code:

publicclassButtons: MonoBehaviour {
PublicTexture buttonTexture;
Privatestringinfo = "" ;
VoidStart () {
//Update, is, called, once, per, frame
VoidUpdate () {
VoidOnGUI ()
// text display
GUI.Label (newRect (50, 200, 200, 50), info);
// the first text button
GUI.color = Color.yellow; // button text color
GUI.backgroundColor = Color.red; // button background color
if (GUI.Button (newRect (50, 250, 200, 30), , Button1, ))
Info = "press Button1", ;
// second picture buttons
GUI.color = Color.white; // button text color
GUI.backgroundColor = Color.green; // button background color
if (GUI.Button (newRect (50, 300, 128, 64), buttonTexture))
Info = "press Button2", ;