How to make an interractive worrld map

I’m creating a scene wherre there is an imported.jpg world map.
How do you divide it into clickable regions?
Note:I’m crreating my own regions and not dividing it into countries that exist in the real world.

Note2: I’m a beginner so please use simple words.

The easiest way to do a click able world map is to make another image. Have each clickable region a different colour. Then when you click the image you can call GetPixel to find the colour at the target location. Read back the colour values to figure out which region you used.

There are a couple of tricks to this, make sure you make the texture read/write enabled. And its easier if you only use one channel of the picture.

1 Like

What about simply using collider as fake areas ?

The shape of the regions will make that difficult. You would need to manually lay out the shape of the polygon collider which would take forever. Same thing if you tried to cut the map into different image files, making each region a slice. The automatic polygon collider would be a square and the adjustments to fit the shape on the image would take a long time as well.

Painting another channel of the image to identify blocks of it is probably both the easiest and most performant solution. The only simpler alternative would be to use large box and circle collides to map out large blocks of regions, leaving large unclickable areas.

2 Likes

Slice the map in photoshop and Make a sprite. Bring it into unity as multiple sprites. Then u can use those unity UI system. I saw somewhere that you can put them inside the scene itself. Then you can use buttons, aligned them as a table then throw in the pieces of the map. Arrange as desired then tweak the space that you want to be clickable ensuring that they don’t overlap, the transparent spaces of the map textures can overlap as long as they don’t affect the clicking part. . . . This should work. . . .

What @Tomnnn said. Maps have very irregular shapes. Splitting it up into multiple sprites or building individual polygon colliders will be a pain. And then you have to rework it every time the artist changes the map slightly. Simply putting in another channel will be much simpler.

@Kiwasi - Not sure if GetPixel and SetPixel and stuff in Unity is any different than Visual Studio, I do however know that in VS back when I was doing stuff on it years ago, GetPixel and SetPixel(I believe it’s called SetPixel) were very slow to use as it had to scan each pixel from the top left down to get to your pixel you wanted.

But of course things change over the years and you may be talking about something completely different than I am lol.

Normally when clicking on a map speed is not that big a deal. I don’t think GetPixel is that expensive for a single pixel anyway. However if this speed was of concern you could use GetPixels and get the entire set of pixels into an array. Then just reference the array as needed.

Well yeah I didn’t really think it would be haahah, just wasn’t sure how slow it was. Just always heard that when I was doing image editing stuff in VS. People always said to use LockBits which is way faster. Not sure if Unity has LockBits though.

I used set pixel and get pixel for a flamethrower effect for a project in college. There was an outer model which was skin and an inner model which was burnt / skeleton. I used set pixel hundreds, sometimes thousands, of times per frame continuously to set pixels on another channel to a color that was used to determine which pixels the skin shader would discard.

An interactive map, to me, sounds like something that everything else will pause while you do. I think it will perform just fine :smile:

1 Like

I’ve used SetPixels it to provide real time updates on multiple screen overlays at run time. I didn’t have any issues either.