Don’t know if this is possible but I have a string value which is the name of the actual new material I need to change. In this case this is ‘newColor’.
Why doesn’t the following work?
ReplaceMaterial((Material)newColor);
void ReplaceMaterial(Material mat)
{
MeshRenderer[] renderers = GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer r in renderers)
{
if (r.sharedMaterial == currentMaterial)
{
r.sharedMaterial = mat;
}
currentMaterial = mat;
}
}