- Home /
How can I make the click area on a GUI texture a different shape?
Ok let me explain this so you not confused. Let's say your making a map of America. You want to be able to click on each individual state for info or something. I don't want images interfering with each other. Any help?
Edit:
I searched all over google and youtube!
Answer by roamcel · Jan 13, 2012 at 10:00 PM
I believe your best call is to render the map on a simple plane, and put it on the 'Ignoreraycast' layer, so that raycasts 'go through it', then just behind the plane with the map, you place actual colliders, for example from prefabbed objects that have a script with a public variable 'statename'.
This should be enough to put you on the right track.
The on;y problem is I would have to put many colliders down for 1 state because states aren't square. At least no most of them
You are correct about the multiple collider issue but alas, the other choice is creating meshes for every single area, and using a 'mesh collider' on them. You see there's no way to avoid colliders if you need to interact with your objects. Regarding 2D, you will just need to set your cameras to 'orthographic' to render correctly in 2D.
They don't have to be a perfect fit, either. You could have some small gaps around the edge, no problem.
In my hex-based game, the colliders for the tiles are all spheres, there's a gap around the edge, but it helps avoid ambiguity.
Answer by robertbu · Oct 09, 2014 at 11:55 PM
You can do this by using a mask with colors. The following answer should get you most of the way there:
http://answers.unity3d.com/questions/516609/empty-spaces-in-buttons-are-detected-by-mouse.html
If you want GUI, make sure to look at the GUI solution in the comment as well as the real-world solution. And if I was not clear, the image with colors for testing does not have to be the same resolution as the original...just the same aspect.
Your answer
Follow this Question
Related Questions
How to Create a Multi Floor Mini Map 1 Answer
GUILayout.Button scales texture wrong 0 Answers
GUI area vs group 1 Answer
Help with minimap 1 Answer
Map Camera 1 Answer