Lerping textures

I got this code but it does not seem to work for textures.Can anybody tell me what I’m doing wrong?

public Material Mat1, Mat2;
public float Sec;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

    float lerp = Time.time / Sec;
    renderer.material.Lerp(Mat1, Mat2, lerp);

}

It does work when I assign two materials with just color but it doesn’t work when the materials have textures. Is there another method for textures?

There is no build in way of lerping textures in unity. I guess what you want to do is blend one texture into another. You could do this with a shader instead, that uses two textures and exposes a “blend” property.

I have made a script and a custom shader just for this:

http://www.sundh.com/blog/2012/09/real-time-blend-2-textures-in-unity/

Hope it helps!

Materials don’t work that way, I’m afraid. Look through the documentation for Material- do you see any ‘Lerp’ function in there?

This is because materials are more complicated than just a few numbers, the way Vectors and Colors are. Each material contains a lot of information which cannot easily be ‘interpolated’ between point A and point B.

However, if all you are trying to do is change the textures, you can use a shader which interpolates between two given texture inputs by some value (which can be assigned in a script). There’s one solution here. I recommend becoming familiar with the shader language Unity uses- it will be extremely useful to you even if (like me) all you ever do are rough hacks of what you need- as long as you know the basics, you can go a surprisingly long way.