Author Topic: World Map 2D Lite Edition - indicating certain countries on world map  (Read 172 times)

nalincy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hello!

I am new to unity. I want to show the world map in a scene with certain countries (known to game) highlighted with a specific color.

I want to know if this is possible with World Map 2D Lite Edition. In the demo of World Map 2D Lite Edition, I see that mouse movement shows the country highlighted with configured color. I want disable this behavior. I want more of a static view. Just to highlight certain countries (down the line certain cities) which are known to game at a given point of time. Is it possible with World Map 2D Lite Edition?

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 4843
    • View Profile
Hi, yes it's possible to achieve that with the Lite edition as well.

Attach this script to any gameobject in the scene with the map (you can create a new empty gameobject and attach this script):

Code
using UnityEngine;
using WPMF;

public class CountryColors : MonoBehaviour {

    WorldMap2D map;

    void Start() {

        map = WorldMap2D.instance;

map.enableCountryHighlight = false;
map.ToggleCountrySurface ("France", true, Color.yellow);
map.ToggleCountrySurface ("China", true, Color.red);

    }
}

The script does the following:

1) It gets a reference to the map API.
2) It disables country highlighting with mouse.
3) It colors France in yellow and China in red.

You'll notice that French Guayana is also colored in yellow. That's because the method ToggleCountrySurface affects all land regions belonging to the given country. If you just want to color the main region of the country use ToggleMainRegionSurface instead. This method is a bit more complex because it accepts more options. So instead of the ToggleCountrySurface("France"...) line, use:

Code
...
int countryIndex = map.GetCountryIndex ("France");
map.ToggleCountryMainRegionSurface(countryIndex, true, Color.yellow, null, Vector2.zero, Vector2.zero, 0);
...

Regards.

nalincy

  • Newbie
  • *
  • Posts: 4
    • View Profile
Thanks a lot for the confirmation and code snippet. I move forward to use it.