Lerp between two materials

I’m trying to make a transition between 2 materials, but I’m not having success as the example given in the documentation.

I need to change a material [Shader: Sprites / Default] to [Shader: Sprites / Diffuse], is it possible?

 public class ChangeMaterial : MonoBehaviour {
     public Material materialA;
     public Material materialB;
     public float duration = 2.0f;
     void Update()
     {
         var sprite = GetComponent<SpriteRenderer>();
         var lerp = Mathf.PingPong(Time.time, duration) / duration;
         sprite.material.Lerp(materialA, materialB, lerp);
     }
}

With this code nothing happens!

What could be wrong?

Every help is welcome!

Quote from the documentation: Unity - Scripting API: Material.Lerp

If you need to animate between unlit and lit you’ll need to make your own single shader that can blend between both states.

1 Like