Fading Materials

What I am looking to do is to fade one material into another on a gameObject, over a period of time. What I currently have is an array of materials which change one by one, each one slighly more similar to the desired material last than the last. Is there a way to dynamically change the alpha on a material, so that they can be crossfaded? If this can't be done on materials then would this be possible with textures instead?

OK, I've built a shader using the Skybox Blended code, and applied it to a material called "Blend". The code for the shader is below.

Shader  "Texture Blend" {

Properties {
    _Tint ("Tint Color", Color) = (.5, .5, .5, .5)
    _Blend ("Blend", Range(0.0,1.0)) = 0.5
    _Tex ("Start Texture", 2D) = "white" {}
    _Tex2 ("End Texture", 2D) = "white" {}

}

SubShader {
    Tags { "Queue" = "Background" }
    Cull Off
    ZWrite On
    ZTest Always
    Fog { Mode Off }
    Lighting Off       
    Color [_Tint]
    Pass {
        SetTexture [_Tex] { combine texture }
        SetTexture [_Tex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
        SetTexture [_Tex2] { combine previous +- primary, previous * primary }
    }
}

I want to change the 'Blend' value in a script, and the site said to use:

skyboxmaterial.SetFloat("_Blend", yourBlend)

However, when I try to call it in the script using:

Blend.SetFloat("_Blend", examplefloat);

I get the error that Blend (the material) has not been identified. Any help?

I don't think this is possible with materials. But depending on how your materials are layed out and what shaders you are using you might be able to achieve the effect you are looking for. These are some of the possibilities:

  1. change the main color. (works only if both materials are using the same texture/shader)
  2. write a shader that is able to crossfade two (or more) materials. There is a shader on the wiki called skybox blended which shows how to do that. However this will only work if both desired materials use the same shader. (actually its only one material with different textures)
  3. fading out using alpha will only work if you are using transparent shaders.

You can crossfade them with the Lerp method of materials. Just input the two materials you want to crossfade between:

I have written a script and a custom shader for this purpose. See files and code here:
http://www.sundh.com/blog/2012/09/real-time-blend-2-textures-in-unity/

Hope it helps!