Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by shads11858 · Sep 05, 2013 at 12:40 PM · guitexturebuttontexture2dimage

Assiging an Image to a Button

I've been looking for hours for an example that explains how to do something I thought would be simply, adding a image file to be used as a button. The examples I've found talk about using Resources.Load("wheat.png") which I put inside a resources folder which I've put everywhere just in case I didn't have in located in the right folder inside my project. e.g. like:

private Texture wheatButton; void Start() { wheatButton = (Texture)Resources.Load("wheat.png"); } void OnGui(){ if (GUI.Button(new Rect(button.x, button.y, 100, 20), wheatButton)); }

Nothing gets displayed and there is no examples of C# code to show how one goes about loading a image apart from saying, use inspector. But I can't see what object or thing you can create to then access in the inspector to link a image, or any examples showing how to do it. I'm sure someone out there has needed to load an image as a texture to use in scripting code before and shouldn't be that complex, any help would be appreciated.

Comment
Add comment · Show 2
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
avatar image ArkaneX · Sep 05, 2013 at 01:06 PM 0
Share

You have to use OnGUI method ins$$anonymous$$d of OnGui (GUI must be uppercase).

avatar image shads11858 ArkaneX · Sep 05, 2013 at 01:16 PM 0
Share

Yeah I typed that code in to cut out some of the other misc stuff, it is OnGUI(), it does work I had it as text before I changed it to an image. It now just comes up as a blank little box. Its just how does on add an images as a texture, I know I can do the button part, its loading that as a texture so I can use it which I'm having issues with

1 Reply

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

Answer by ArkaneX · Sep 05, 2013 at 01:52 PM

Please load the image using

 wheatButton = (Texture)Resources.Load("wheat");

without .png extension. If you have Resources folder inside Assets folder, then this should work.

Comment
Add comment · Show 2 · 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
avatar image shads11858 · Sep 05, 2013 at 02:18 PM 0
Share

Who would have thought it would be that simple. Thanks for that, images at least shows and gives me something to work with. $$anonymous$$uch appreciated.

avatar image shads11858 · Sep 05, 2013 at 02:25 PM 0
Share

The funny thing was the forums I read with examples of Resources.Load had .png after it so thought it needed that. Fail

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.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Empty spaces in buttons are detected by mouse 2 Answers

Making texture cover whole button 1 Answer

GuiTexture (Touch button) unfollow camera! 1 Answer

GUI Style Issue-- Texture not changing 2 Answers

Same BackGroung For All Screen Resolution 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges