Changing Colors of Multiple Materials on One Object

Good evening all,

I have an object that has multiple materials and was curious on how to make them change color through C#. The command that I found was reendererObject.material.SetColor(“Hat”, Color.red);. Is this the right code to do that? The first argument of SetColor says its an int nameID…not sure what exactly Im to put in the first argument there.

Id hoped it would have been the name of the material and then the color to change it to. It doesnt seem to do anything when calling that line of code for each corresponding part of the object I want to change color. I hope what Im saying make sense. Anyone know how to access each material of one object?

Thanks!

Negative. What you are doing is calling for the Renderer Object, not the material of that object. I figured it out. Here, for future reference. Thanks for the help anyway!

    public Material[] = mats;
    
    void ChangeMaterials()
    {
          mats[0].color = Color.red;
          mats[1].color = Color.green;
          //  etc...
    }