You seem to want different colors for different images. You can e.g. group the Images and colors together.
public Image clay, sand, loam, silt, siltyClay, siltyLoam, loamySand, sandyLoam, siltyClayLoam;
[System.Serializable]
public class ImageColorPairs
{
public Image[] images {get;set; } /* associate Images */
public Color targetColor { get; set; } /* ..with a target color */
}
private ImageColorPairs[] pairs; //Declare here but initialize later. Can't initialize these objects (error: referencing non-static field..)
public void InitializePairsOnce()
{
/* Make up array of Pairs here */
pairs = new ImageColorPairs[] {
new ImageColorPairs() { images = new Image[] { sand }, targetColor = Color.green } ,
new ImageColorPairs() { images = new Image[] { clay, loam, silt, siltyClay, siltyLoam, loamySand, sandyLoam, siltyClayLoam }, targetColor = Color.white }
};
}
public void ImageColor()
{
/* Now setting the colors is easy! :) */
foreach (var pair in pairs)
{
foreach (var image in pair.images)
{
image.color = pair.targetColor;
}
}
}
You can also make it use more basic data strucutres like a your own ImageTuple, which would then associate each image individually a color. But up there you seem to only have two basic groups, so it's less work to just associate a color for a whole array of images.
With such a class you would do it like
[System.Serializable]
public class ImageTuple
{
public Image image;
public Color targetColor;
public ImageTuple(Image img, Color col)
{
image = img;
targetColor = col;
}
}
private ImageTuple[] imageTuples;
public void InitializeTuplesOnce()
{
imageTuples = new ImageTuple[]
{
new ImageTuple(clay, Color.green),
new ImageTuple(sand, Color.white),
//.. the rest
};
}
public void ImageColor()
{
foreach (var pair in imageTuples)
{
pair.image.color = pair.targetColor;
}
}
List<>.