how can i get renderer.material.lerp() to work? … i’ve copied the code from the documentation:
// Blends between two materials
var material1 : Material;
var material2 : Material;
var duration = 2.0;
function Start () {
// At start, use the first material
renderer.material = material1;
}
function Update () {
// Ping-pong between the materials over the duration
var lerp = Mathf.PingPong (Time.time, duration) / duration;
renderer.material.Lerp (material1, material2, lerp);
}
…I’ve made 2 simple materials and dumped them onto the script (which is placed on a simple cube).
when I run it I get a cube covered in the “dirt_mat” - which is my material no. 1 … but nothing else happens.
Have I misunderstood how to use this? or just missed something obvious?
thanks - at least something is happening now … I changed the colors and I see the texture of material1 change color.
but… i was hoping to find a way to fade the entire material from one to another, not just the color.
So, if the code pasted above (in my first post) only lerps between the colors of the materials … it’s really no different than this:
(sample code from material.color documentation)
// Fade the color from red to green
// back and forth over the defined duration
var colorStart = Color.red;
var colorEnd = Color.green;
var duration = 1.0;
function Update () {
var lerp = Mathf.PingPong (Time.time, duration) / duration;
renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp);
}
Thanks Bjerre it does exactly what I was looking for (and thought material.lerp() did!).
One quick question though - and this is where I yet again expose myself as a complete newbee - How can I access the properties of the shader from a javascript? I’d like to do a Mathf.PingPong on the _Blend property of the shader, my feeble attempt so far is this:
var duration = 2.0;
function Update () {
var lerp = Mathf.PingPong (Time.time, duration) / duration;
Shader.Find("_shaders/ChangeMaterial")._Blend = lerp;
}
…which throws the error: ‘_Blend’ is not a member of ‘UnityEngine.Shader’
…which makes sense, but how do I go about doing this?
Hi, I’m using unity 5.3.4 and material lerp still not work?
I have made a simple cube and a script with 2 textures as example.
Using the shaders, the resulting texture is a bit grayed…
any ideas?
thanks
I needed the same thing and tried this recommendation with the shader. Seems to work pretty good.
One more question thought, as I am no shader wizard, how do I make this unlit? I need it to not respond to lighting at all.