- Home /
Clickable map
Hello Everyone,
I am starting to explore Unity 3D to use it as a game engine for my project an I do have a question . I am trying to make my first scene in which I will have a rotating globe and I need to have a script that allows me to specifiy certain countries to be clicked on and another scene should be loaded... Pls if anyone can explain to me how to do it in details I will appreciate it
Answer by ScroodgeM · Aug 29, 2012 at 07:00 PM
solution 1 - colliders
split a globe model to sub-meshes with countries silhouettes with accuracy you need. now you can catch clicks separately to each country by mapping this meshes to countries
solution 2 - masks
make a alpha-masks for each country. ask should be a texture with alpha-selected country silhouette. on click you just should check clicked pixel (pixel can be gotten by raycast) on each texture and where this pixel is enabled (mask present) - this is your country. this way also lets you highlight countries on mouse hover easily.
this is example of globe texture:
imagine this texture on globe with sphere collider. once we raycast globe from mouse position with hit returned, we got texture coordinates of this hit.
and this is the mask of Russia country:
both textures are (and should be) the same size. now check clicked coordinates from first texture on this texture with transparency only channel. if a pixel in clicked coordinates is white, we clicked Russia country, or else - we clicked somewhere else.
don't post comments as answers.
explained second solution, first is too hard 8)
Btw. It seems this is a quite similar question to this one:
good idea about different colors for areas and single map for all 8) simple shader improvement that let you highlight covered by mouse (or some other pointer) area will make a nice tool 8)