0
\$\begingroup\$

I have a function where you click on an object and it changes the color and emission of a specific material, every object has multiple materials with different order.

var emissionColor = mat.GetColor("_EmissionColor");
List<Material> materials.AddRange(t.GetComponent<MeshRenderer>().materials);

 foreach (var m in materials)
    {
        if (m.name.Equals(matName))
        {
            //Debug.Log(m.name);
            m.EnableKeyword("_EMISSION");
            m.color = mat.color;
            m.SetColor("_EmissionColor", emissionColor);

        }
    }

So far I'm changing the color once but I would like to have it transition into a different color every 10 seconds, I tried using the animator but it keeps changing the wrong material. Is there a way to do this animation in code?

\$\endgroup\$
0
\$\begingroup\$

I didn't want to delete this question because it might help someone else facing this problem. Basically I used the code above in a function (ChangeColor) that I call twice with a different mat every time. In order to get that delay I used Invoke("ChangeColor", delay); for the second time that I change the material's color.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.