How do I assign materials to multiple GameObjects at once?

Hi! I’m working on a game where my gun changes colour depending on the amount of kills I have. The problem is my gun is made out of 100 gameobjects. I can’t change the colours of the objects unless I do it individually:

var changeColourBlock : GameObject;
var redMaterial : Material;
var gunKills : int;

if (gunKills >= 275)
changeColourBlock.renderer.material = redMaterial

How can I change the colour of multiple gameobjects in code without having 100 different gameobject variables and 100 lines of code on top of this?

P.S I have tried using:

var changeColourBlocks : GameObject[]; 

But this doesn’t work.

Any help would be appreciated, thanks!

With gameObject.FindComponentsInChildren(MeshRenderer) you can find all mesh renderers in children of the gun.

This method is very slow so you should use it in Start() once and not every time you want to get all meshrenderers