change material in each material unity code example
Example: how to set material c unity
Renderer rend = GetComponent<Renderer>();
if (rend != null){
rend.material = newMaterialRef;
}
Renderer rend = GetComponent<Renderer>();
if (rend != null){
rend.material = newMaterialRef;
}