Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created February 22, 2023 11:29
Show Gist options
  • Select an option

  • Save unitycoder/e2d54fa3dae0c8570246efb656f694dc to your computer and use it in GitHub Desktop.

Select an option

Save unitycoder/e2d54fa3dae0c8570246efb656f694dc to your computer and use it in GitHub Desktop.
How to do a selectable map (using texture pixel colors as ID)
// C#
int continent = (int)(pickedColor.g*12.75f+0.5f);
int regionLow = (int)(pickedColor.r*12.75f+0.5f);
int regionHigh = (int)(pickedColor.b*12.75f+0.5f);
int region = regionHigh*13 + regionLow;
https://answers.unity.com/questions/289506/how-to-do-a-selectable-map.html
Since some are confused by this approach, here's it a bit more in detail:
I've just created an example selection texture for the map the OP posted. It uses the green channel to specify the "continent" and the red channel (followed by blue) to specify the region. I used a color steps of 20 so each color channel can have 13 different states (12 are only used because 0== black is never used as region). That means i could have 12*12*12 regions which equals 1728.
In my example to get the continent and the region index i just do
https://www.dropbox.com/s/jr7whf2wesro7w8/Map_WithColors.png?dl=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment