Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by beco13 · Sep 02, 2011 at 03:31 AM · guibuttongui.window

Is there any other way for button overlaping?

Hi guys, I've got some problems using GUI Buttons

I need to do this kind of scripting :

A scroll view that has images, within

An Image has an inner -image within that is clickable.

Both the image an inner image should be clickable.

I use GUI.Button to show the images. Usually I create the inner image within a separated window. While in this situation is I can't make the inner image within another window since I have to do it in a scroll view.

for example :

     GUI.BeginGroup(Rect(15, 40, 380, 575));
     button[i] = GUI.Button( Rect( 5, topButton , 305, 138), "", Panel);
     if(GUI.RepeatButton ( Rect( 120, topButton + 75, 40, 40), "", script[i].SkillIcon))
     GUI.EndGroup();

in short : I want to able to click the panel and skill icon. but the skill icon is in the panel itself, while the panel is in a scroll view. Any ideas on solving this problem?

Comment
Add comment · Show 3
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 SilverTabby · Sep 02, 2011 at 05:12 AM 0
Share

So your problem is that you have two buttons on top of each other, so that the one on top is the one you want, but if you click on the inner one, then both of them go off, right?

If that is your problem, I would just leave the buttons where they are, but ins$$anonymous$$d of feeding the button into an if statement, I would ins$$anonymous$$d feed the buttons into two vars, and then only perform the action of the inner button if both are pressed.

avatar image beco13 · Sep 02, 2011 at 05:23 AM 0
Share

@SilverTabby : that would be nice if I could do that..But the problem is the top button doesn't perform it's action since it's rendered on top of the other button. Obviously your suggestion is not working... :(

avatar image Sigil · Sep 02, 2011 at 05:45 AM 0
Share

@SilverTabby I threw this together in a project real quick, and it seems like the background button eats the mouse click event and so the the smaller button within the larger one never gets clicked.

2 Replies

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

Answer by Sigil · Sep 02, 2011 at 06:17 AM

You can use a repeat button and render the second button within it with a pressed style, like so:

 function OnGUI()
 {
     if (TextureToShow == null)
         return;
     
     var tLargeButton:Rect = Rect(0, 0, TextureToShow.width, TextureToShow.height);
     var tSmallButton:Rect = Rect(0, 0, TextureToShow.width / 2, TextureToShow.height / 2);
     
     if (GUI.RepeatButton(tLargeButton, TextureToShow))
     {
         // Put code for large or small button here (both will hit it)
         
         if (tSmallButton.Contains(Event.current.mousePosition))
         {
             // Put code for only the small button here
 
             var tPressedStyle:GUIStyle = GUIStyle(GUI.skin.button);
             tPressedStyle.normal = tPressedStyle.active;
             
             GUI.Button(tSmallButton, TextureToShow, tPressedStyle);
         }
         else
         {
             // Put code for only the large button here
 
             GUI.Button(tSmallButton, TextureToShow);
         }
     }
     else
         GUI.Button(tSmallButton, TextureToShow);
 }
Comment
Add comment · Show 5 · 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 beco13 · Sep 02, 2011 at 06:51 AM 0
Share

I don't really get it....but forgot to mention, I'm not using a mouse because I'm developing in iOS system...can you explain this in more detail...I hope this can give me some enlightenment...

avatar image Sigil · Sep 02, 2011 at 06:59 AM 0
Share

Well I'm assu$$anonymous$$g this is your problem: You can't press the small button that's within the large button, only the large button gets pressed. Is this right?

The code above says, while the large button is being pressed, if the mouse happens to be in the smaller button's area, consider it pressed too.

Someone else will have to chime in on the iOS part, I'm thinking you can replace that Event.current.mousePosition with something like Input.GetTouch(0).position or similar.

avatar image beco13 · Sep 02, 2011 at 07:04 AM 0
Share

your assumption is correct....hmm,...I wonder...I'll try your suggestion..

I'll let you know soon if this problem solved..

avatar image beco13 · Sep 02, 2011 at 08:08 AM 0
Share

@Sigil: okay your code is working...but somehow...the bigger button code is also executed...have you got any idea to exclude the bigger button code???

avatar image Sigil · Sep 02, 2011 at 05:13 PM 0
Share

I added some comments to indicate where you can put your code to get the desired result.

avatar image
0

Answer by Waz · Sep 02, 2011 at 05:54 AM

You could disable the outer button, or draw it as a Label in a Button style, whenever the mouse is inside the Rect of the inner button.

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 beco13 · Sep 02, 2011 at 06:49 AM 0
Share

forgot to mention....I'm doing this project in iOS...so, there'll never be a mouse... >.< btw, thank you for your answer, you gave me a new perspective....

avatar image Waz · Sep 02, 2011 at 06:59 AM 0
Share

The technique would still work, except you would be checking touches ins$$anonymous$$d. The point is to avoid the outer button accepting the event before the inner button gets a chance to.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable one GUI Button with my Mouse Scroll Wheel? 1 Answer

GUI.Label positioning for many device resolutions 1 Answer

GUI, making main page lead into an instructions page 2 Answers

How to get Rect from scene Button ? 1 Answer

Unity 5 GUI system 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