Interactive world map with selectable regions

I would like to make an interactive world map that consists of clickable regions, just like in this map.

alt text

I have create two textures, one for the display of the world map and the other is a painted texture where each province is colored in a different way.

When I click on the map I send a Raycast and get the texture coordinate that hit.

This is my C# code

public class MouseManager : MonoBehaviour {

    public Texture2D id_map;

    public Color color;

    private void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector2 textcoord = hit.textureCoord;

                textcoord.x *= id_map.width;
                textcoord.y *= id_map.height;
                
                color = id_map.GetPixel((int)textcoord.x, (int)textcoord.y);


            }
        }
    }
}

I want to change provinces color to the color of it’s owner.

For example province of Provence belong to France and has blue color, province of England belong to United Kingdom and has red color…

Do you know any ways to do that?

Thanks for the help!

Good day.

Why are you reading the pixel? If you want to change the color of all region, you only need to have all textures stored (texture for each region in each color) , and detect the object (region) you clicked. You can also do this tieh Event System, or with colliders and use

OnMouseOver() 
OnMOuseDown()
OnMOuseExit()

Then just change the object sprite.

Bye!

Thanks for your reply @tormentoarmagedoom

I am reading the pixel because in the painted map each province is colored in a certain way and in game when I click the mouse I send a Raycast and get the coordinate that I hit. Then I compare the color at that pixel and get the appropriate province.

My problem is how mark in game the provinces with the same color for the same country.