I would like to make an interactive world map that consists of clickable regions, just like in this map.
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!