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 kiwi koder · May 25, 2013 at 12:20 AM · texturebuttoncolor

How to use part of an image for a button

I am trying to create a region select type thing with a map of a country. Below is similar to the image I will be using. I was wondering how you would create each color(region) on the map do a different function, so basically make each color its own button. The image is currently in unity as a texture.

alt text

newzealandregions.png (29.9 kB)
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
0
Best Answer

Answer by robertbu · May 25, 2013 at 12:28 AM

One solution is to switch based on the color at the position clicked. Use a form of Physics.Raycast() that takes a RaycastHit parameter. Use the textureCoord property in the RaycastHit to access the pixel of the texture hit. Execute appropriate code based on the color.

Note if your graphics are not pure colors like you have in the diagram above, you can put a simplified version of the map on top on using a separate plane with a very slight alpha.

Comment
Add comment · Show 3 · 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 kiwi koder · May 25, 2013 at 12:31 AM 0
Share

Thankyou, so the other image would have very slightly different alpha for each region?

avatar image robertbu · May 25, 2013 at 01:36 AM 0
Share

You could use alpha, or you could use a color. The reason I indicate a "slight" alpha is because of a bug or optimization in Unity. I was playing with a similar concept a while back using the color. I found that if I did a GetPixel() on a pixel that had 0 for an alpha, the color returned was white (1.0, 1.0, 1.0, 0.0) no matter what the color in the original texture. But if I assigned an alpha of 1 (in the range of 0 to 255) in Photoshop, GetPixel() would return the correct color. So that is like having an alpha of .004 in terms of the floats Unity uses, so the texture was not visible.

avatar image kiwi koder · May 25, 2013 at 02:19 AM 0
Share

Ok that makes more sense now. Cheers

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

12 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

Related Questions

How to have correct color on imGUI Buttons (as dynamic textures) avoiding multiply effect ? 1 Answer

It is possible to use texture atlases like button? 1 Answer

How to make texture fit in GUI button? 1 Answer

How to change the color of predefine portion of the texture? 1 Answer

Making a button in unity iphone? 3 Answers


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