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 user-9719 (yahoo) · Feb 26, 2011 at 02:43 PM · guibuttonoverlap

Overlapping GUI buttons

Hi, I would like to create a GUI piano keyboard. I have tried using GUI.Button for the white and black keys but the overlapping click areas are not ideal. Is there a better approach to this?

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 Jesse Anders · Feb 26, 2011 at 04:47 PM

I don't use the GUI system that much, so I'm not that familiar with it, but I'm not aware of any support for non-rectangular click areas. (If I'm wrong, I'm sure someone will correct me.)

In any case, I probably wouldn't use the GUI system for this, but would instead implement it manually. Although I haven't tested this, here's what I'd try first:

Represent all the keys using bounding rectangles; you can use the Unity Rect struct (and its Contains() function) for this.

For the white keys, size the rect so that it fully contains the key. When checking to see what key has been clicked, check all the black keys first, and then the white keys, and choose the first key for which the bounding rect contains the query point. Unless I'm overlooking something, this should have the effect of handling the irregular shapes of the white keys correctly.

It'll be a little more work than using the GUI system, but I think it will probably give you better results. (Again, unless there's functionality available that I'm not aware of.)

Also, you might be able to accomplish the same thing using the GUI system by creating the controls in the order described above (black keys and then white keys), but only using Button() controls until a click was detected, and using Label() controls (or something similar) thereafter. That's speculative though; I'd have to try it before saying with certainty that it would work.

Comment
Add comment · Show 1 · 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 user-9719 (yahoo) · Feb 28, 2011 at 03:21 PM 0
Share

Thanks Jesse, I think I'll try your manual way.

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

No one has followed this question yet.

Related Questions

button drawn last not triggered 0 Answers

GUI Button overlap problem 1 Answer

Overlapping GUITexture UI Buttons 2 Answers

Overlapping buttons? 0 Answers

GUI.Label positioning for many device resolutions 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