- Home /
UI Button with special collider ( Unity 4.6 )
Hi!
I'm making a Risk kind-of game and I'm using Ui Images for the countries, but my problem is that UI Button uses the image boundaries so if my countries overlap the input fails a bit.
Is there any way of modifing the collider unity uses for the button input detection ?
I'm open to other suggestions!
Thanks!
How do you want it to work?
Technically it's impossible to have two objects both clickable that overlap so you have to have a way to decide which one is being clicked.
Do you want the one the mouse is over to be selected until leaving that button entirely for example?
I was thinking something more in the lines of what a Polygon collider is for a normal sprite.
I could use normal sprites but i would lose all the functionality of the UI Button wich is not hard to code but its really confortable
Not familiar with Polygon collision but you can add an event for pointerEnter and pointerExit for the UI button.
You can also move the country button to the bottom of the UI in pointerEnter, which somewhat stupidly means that's the uppermost UI element.
The event system seems complex at first but definitely worth learning as it's pretty powerful and not that hard to learn.
With your polygon collider how would it tell which one to click if they overlap?
Polygon collider is basically a mesh collider for 2D objects. It guarantees there will be no collisions. But using normal sprites might be less eficcient that using Unity's UI. But as I have no way of adding a custom collider for the buttons i think I'll have to do that
Answer by Mmmpies · Jan 12, 2015 at 08:39 PM
Try this then, add an event to the button. On the button click Add Component -> Event Trigger
Click on Add New Event Type
Select PointerEnter and click on the plus button. Drag your button onto the slot that appears.
then in the drop down select RectTransform -> SetAsLastSibling
Do that for each button and you should be sorted.
EDIT:
OK so that isn't working for you, I've been thinking about what you might be doing. When you say overlap, does the currently selected territory expand so it's larger than the others? Is that the issue?
Also, just thought of this, what if you create a transparent image of the territory that doesn't overlap and use that as the button rather than the image of the territory the player can see?
I'll have the same problem, If I have A and B above eachother i might want to click B but A will be on top
Can you post an image as I'm having trouble visualizing the issue?
Like I said you have to be able to pick which button we want to select, telepathy is out of the question at the moment (although an insider I know at Unity reckons they should have it cracked in Unity 7) ;¬)
Your answer
Follow this Question
Related Questions
How can I make an image maintain it's aspect ratio in Unity UI? 2 Answers
OnMouseUp open an external file 0 Answers
bug or a feature ?? 0 Answers
Unity4.6 gui working with sprites on different resolutions 1 Answer
Is there a bug in Unity 4.6.0? 0 Answers