Basic method:
public static bool Button(Rect position, GUIContent content);public static bool Button(Rect position, string text);public static bool Button(Rect position, Texture image);public static bool Button(Rect position, GUIContent content, GUIStyle style);public static bool Button(Rect position, string text, GUIStyle style);public static bool Button(Rect position, Texture image, GUIStyle style);
Example:
1.
public static bool Button(Rect position, string text);
Code-
1 void ongui () {2 if (GUI. button (New rect (10, 10,100, 50), "button") 3 {4 print ("the user clicked the button"); 5} 6}
2.
public static bool Button(Rect position, Texture image);
Code-
1 Public texture btntexture; 2 void ongui () {3 if (GUI. button (New rect (10, 10,512,256), btntexture) 4 {5 print ("the user clicked the button"); 6} 7}
3.
public static bool Button(Rect position, GUIContent content);
Code-
1 Public texture btntexture; 2 void ongui () {3 if (GUI. button (New rect (10, 10,512,256), new guicontent ("button", btntexture) 4 {5 print ("the user clicked the button"); 6} 7}
4. tooltip
1 void ongui () {2 if (GUI. button (New rect (10, 10,120,100), new guicontent ("button", "This is a button") 3 {4 print ("the user clicked the button "); 5} 6 GUI. label (New rect (10,120,100, 20), Gui. tooltip); 7}
Guistyle needs to be defined and imported in advance, so it will not be written if it is not done yet;
C # compile the button control for the basic GUI of Unity