• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Jose · Nov 21, 2010 at 06:09 AM · guibuttonimagepng

GUI Button using .png image?

I want to create a GUI button with a .png image I imported to my game assets folder. It is 100x30.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
13
Best Answer

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); }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

How to change button image on click 2 Answers

Problem with icon in GUISkin 0 Answers

GUI looks Awful! 0 Answers

Another quality problem with .png GUI graphics 1 Answer

Assiging an Image to a Button 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges