For Array:
Use a for loop to loop over the image array then compare the name. If they match, deactivate them.
public Image[] image;
void activateImage(string imageName, bool enable)
{
for (int i = 0; i < image.Length; i++)
{
if (image[i].name == imageName)
{
image[i].enabled = enable;//Good for performace
// OR
//image[i].gameObject.SetActive(enable);
}
}
}
Usage:
Activate
activateImage("nextImage", true);
Deactivate
activateImage("nextImage", false);
For Dictionary:
Dictionary<string, Image> image = new Dictionary<string, Image>();
void activateImage(string imageName, bool enable)
{
if (image.ContainsKey(imageName))
{
image[imageName].enabled = enable;//Good for performace
// OR
//image[imageName].gameObject.SetActive(enable);
}
}
To add Image to Dictionary:
public Image myImage;
image.Add(myImage.name, myImage);
or
image.Add("myImageName", myImage);
Dictionary<string, Image>does sound like the way forward. Where did you get stuck with that? Creating the dictionary, or using it? Are you able to use LINQ? If so, justvar dictionary = Images.ToDictionary(image => image.Name);or similar should work...