I have a world map which I want the player to be able to click on the different countries and have it flip an appropriate bool. Here’s a quick example of what I’ve already designed, using colliders and the mouse button.
void OnMouseDown() {
canadaselected = true;
GetComponent<SpriteRenderer> ().color = Color.red;
}
The problem is that the current way I’ve done it means I need to write a separate script for each country and attach it to each individual sprite, which would mean nearly 200 short, individual but almost identical scripts (the only line different would be the name of the bool eg. ukselected, brazilselected, chinaselected).
Is there any other way to do this? One that could compress it into a single script I could attach to all the sprites instead of writing separate scripts? Or maybe a way that OnMouseDown could know which sprite it was over and flip the appropriate bool (for example if the bool is canadaselected and the sprite is named ‘canada’)?