- Home /
Answer by duck · Nov 21, 2010 at 07:37 AM
If you're using OnGUI for this, you can either make a direct texture reference in your script, and use that value in the GUI.Button command:
var btnTexture : Texture;
function OnGUI() {
if (GUI.Button(Rect(10,10,50,50),btnTexture)) {
Debug.Log("Clicked the button!");
}
}
Or, you need to create a custom GUI Style, to use with it, and drag your imported png texture into the appropriate "background" slots in the Style's inspector properties (eg, under the "Normal", "Hover" and "Active" slots). Then use that Style for the button:
var customGuiStyle : GUIStyle;
function OnGUI() { GUILayout.Button ("I am a custom-styled Button", customGuiStyle); }
Your answer
Follow this Question
Related Questions
How to access SourceImage component of a button in new GUI 4.6 1 Answer
How can I resize an image and save it to disk ? 6 Answers
Buttons become invisible when changing color (on Button or on Image) in script -1 Answers
How to change button image on click 2 Answers
Unity ruins image horribly 3 Answers