Adding a Color Change Script to a Model

Having a previous question of mine answered on here I was able to obtain a script that changed the colors of the materials on a model I attached it to. It works like it should and I thank he who showed me. However there is something I don't understand. I have 2 tree models. Model A, I apply the script too, and the material for the Bark of the tree changes color, not the leaves. (I want the leaves to change.) Model B I change it to, and it changes the colors of the leaves, not the bark. So why is it working differently with different models? The only thing I can think of myself is that when I click on each tree and look at the Inspector, it shows the materials on the model. Model A has 2 materials, the first one it shows is that bark. Model B also has 2 models, the first one it shows is the leaves. Does it only apply to the first material shown? And if this is the problem, how can I get it to attach to the material I want? Any help is appreciated.

You need to use the array renderer.materials[]. The code renderer.material is just a shortcut for renderer.materials[0], accessing the "first" material, but they aren't in a specific order.