Hello, I am trying to make a small game and in this game there will be a world map and the players will be able to interact by clicking on this map, but I do not know how it would be effective or logical to do this. I was cutting the countries from the world map, putting them as images in Unity and then adjusting them continent by continent, but when it comes to interaction I tried event trigger, but since the alpha part around my country is a little big, in countries like Brazil, this prevents some countries from being clicked. In this case, I don’t know how to do anything. How can I unite the country with its borders exactly, without the transparent part, or even if I do, how should I do the interaction event normally? can you help please?
I believe you can create custom hitboxes for sprites. In the sprite editor, there’s an option to do a ‘Custom Physics Shape’
When you select that, you can have Unity generate a shape for you and it will take the alpha into account.
Bear in mind that it will try to use very few vertices so it will be quite rough. Increasing ‘Outline Detail’ will make it better, but you can also refine it manually.
This is ‘Outline Detail’ = 0 vs ‘Outline Detail’ = 1 on a sample sprite
Outline Detail = 0
Outline Detail = 1
I believe if you keep this tight, you can eliminate the overlaps you are experiencing
Even if I set the hitbox of the object, I cannot run the code. Even though the polygon collider is 2D, it does not detect it strangely when I click on the object. I use the OnMouseDown
command, but it does not work, I do not understand why.
You need to add a collider to the sprite. Use a PolygonCollider2D
and it will automagically use the custom physics shape you defined.
Here’s a quick video of what you need to do
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.