Fading Between 2 Materials?

Hi,

We need to fade between 2 materials based on collisions.

We have started with just a timed script to do so but it’s not working properly. It should just switch between the 2 materials based on the time.

How would we go about doing this and how would it be based off collisions with layers? Would this be possible with using the Unity’s terrain.

// 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 : float = Mathf.PingPong (Time.time, duration) / duration;

    renderer.material.Lerp (material1, material2, lerp);

    }

Actually your code is EXACTLY the same as the example for Material.Lerp from the resources (http://unity3d.com/support/documentation/ScriptReference/Material.Lerp.html)

To get the fading to work, as you probably expect it. Follow this: http://forum.unity3d.com/threads/8936-can-t-get-material.lerp()-to-work

And to do this based on collisions, implement the functions OnCollisionEnter() and OnCollisionExit(), if I remember right.