- Home /
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?
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.
@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... :(
@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.
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);
}
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...
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.
your assumption is correct....hmm,...I wonder...I'll try your suggestion..
I'll let you know soon if this problem solved..
@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???
I added some comments to indicate where you can put your code to get the desired result.
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.
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....
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