- Home /
imaged text button
i want to make a imaged/labeled button. image - text, what is i need to use?
Answer by Statement · Mar 29, 2011 at 03:37 PM
You could publish the GUIContent it would use. This allow you to set text, an image and a tooltip. If you don't want to use text or tooltip, just leave them out.
var buttonContent : GUIContent;
function OnGUI() { if (GUILayout.Button(buttonContent)) { // Handle the press } }
If you rather want to make a button with a custom style, you could either make a new style in a GUISkin or define the style directly on the script.
var buttonStyle : GUIStyle; var buttonContent : GUIContent;
function OnGUI() { if (GUILayout.Button(buttonContent, buttonStyle)) { // Handle the press } }
Or with a custom skin/style:
var customSkin : GUISkin; var buttonStyle : String = "button"; var buttonContent : GUIContent;
function OnGUI() { GUI.skin = customSkin; if (GUILayout.Button(buttonContent, buttonStyle)) { // Handle the press } }
Answer by robertmathew · Mar 29, 2011 at 03:28 PM
var btnTexture : Texture;
function OnGUI() { if (GUI.Button(Rect(10,10,50,50), btnTexture)) { Debug.Log("Clicked the button with an image"); } }