- Home /
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?
Answer by StephanK · Nov 01, 2011 at 09:32 AM
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.
Answer by ellens · Sep 06, 2012 at 07:44 AM
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!
Answer by syclamoth · Nov 01, 2011 at 09:33 AM
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.
Your answer
Follow this Question
Related Questions
Lerping multiple materials of a gameobject within a coroutine 0 Answers
How to Lerp between two materials 1 Answer
Lerp isn't completing itself 3 Answers
Lerp doesn't work after using a lerp? 1 Answer
How do I add multiple points using Lerp? 3 Answers