How do I store the colors of children in an array?

Okay, so I’m trying to script in a little code that will make an enemy in my game flash red when I attack them. I already have figured out how to make them turn red:

foreach (Renderer r in GetComponentsInChildren ()) {
r.material.color =;

but I can’t think of a way to make them return to their original colors. I was thinking I could store each children’s original color in an array but I don’t know a good way to do that. Please help

You already know how to get the renderers that contain the colors. You just need declare an Color array variable and store the colors there before changing them to red. Do something like this:

//Get ahold of the renderers
Renderer[] renderers = GetComponentsInChildren<Renderer>();

//Declare a color array
Color[] originalColors = new Color[renderers.Length];

//Save the original colors into the array
for(int i = 0 ; i<originalColors.Length ; i++)
    originalColors _= renderers*.maetrial.color;*_

//Now that the original colors are saved you can change the color to red

foreach(Renderer r in renderers)
r.material.color =;

//EDIT: If this code is inside a coroutine then you can do
// yield return new WaitForSeconds(0.5f);

//And then when you want to turn them back to the original color you just do
for(int i = 0; i<originalColors.Length; i++)
renderers_.material.color = originalColors*;

Note that in this code I wrote, renderers and originalColors are local variables, but you could easily turn them into fields instead so you can use them elsewhere in your code, or if you are already using a coroutine for this code then you could just yield for some time and use them as they are here.