MissingComponentException: There is no 'Renderer' attached to the "Enemy_PF" game object

I’m trying to flash an enemy when hit.

The code is as follows:

public function Hit()
{
animation.Play(“hit”);
Debug.Log(“hit”);
renderer.material.color = Color.red;
}

But when the program runs, the enemy is not turn to red at all, and console displays following message:

MissingComponentException: There is no ‘Renderer’ attached to the “Enemy_PF” game object, but a script is trying to access it.
You probably need to add a Renderer to the game object “Enemy_PF”. Or your script needs to check if the component is attached before using it.

The gameobject is an instantiated-in-editor prefab, and the prefab contains a 3ds max imported mesh.
So the gameobject should have a renderer.

How can I avoid the error and flash it?

The renderer is presumably not of the top level object but a child.

  GetComponentInChildren(Renderer).material.color = Color.red;

In my case, the answer is the following code:

private function applyColor(a_color: Color)
{
var renderers: Component = GetComponentsInChildren(Renderer);
for (var renderer: Renderer in renderers)
renderer.material.color = a_color;
}

I built the enemy mesh with many objects in 3ds max(in this case, 52 including biped parts. the enemy is a humaniod robot, and I had to built body parts with separated objects), and Unity seems to retain individual objects when importing.
And Unity seems to assign one renderer per object.
So I must set up all renderers.
Now I am concerned of the performance…