how to add sprites name in code ?
i have 42 sprites, and i want them to access in my code. to select random 21 of them. how can i add them in a list or array? i want to color them red and to other sprites green . this is not working folder is named MAPS and sprites are tagged as country any idea to access them ??
Sprite[] countries = Resources.LoadAll<Sprite>("MAPS");
sr = GetComponent<SpriteRenderer>();
names = new string[countries.Length];
for (int i = 0; i < names.Length; i++)
{
names[i] = countries[i].name;
//0 = red
//1 = green
if (UnityEngine.Random.Range(0, 2) == 0)
{
this.GetComponent<SpriteRenderer>().color = Color.red;
}
else
{
this.GetComponent<SpriteRenderer>().color = Color.green;
}
}
Comment