Lerp RenderSettings skybox

I want to switch my skybox from a day material to a night material for this I use :

Material night;
int skyboxflag = 0;
int flag = 0;
float t;
public float smooth = 1;

void Start () {
    night = Resources.LoadAll("Night_mat",typeof(Material))[0] as Material;

}

void Update () {
if (skyboxflag == 1) {
        if(flag == 0){
            t = Time.time;
            flag = 1;
        }
        RenderSettings.skybox.Lerp(RenderSettings.skybox, night,(Time.time - t)/smooth);
        if(Time.time - t > smooth){
            skyboxflag = 0;
        }
            }
}
void OnTriggerEnter(Collider other)
{
    if (other.gameObject.name == "Avatar") {
        skyboxflag = 1;

            }
    }

but nothing happens I keep having the day skybox.

what is the correct way to change the skybox smoothly from a material to another

Thank you

I have the same problem in Unity 5. I was using http://wiki.unity3d.com/index.php?title=SkyboxBlended in Unity 4, but that shader no longer works in Unity 5. Does anyone have an idea how to do skybox blending in Unity 5?

EDIT: Found a fix!

This Skybox Blending shader works in Unity 5.

using UnityEngine;
using System.Collections;

public class dayknight : MonoBehaviour {

public Material mat;
public Material day;
public Material skyBox;


float t = 0.02f;
float a;
// Use this for initialization
void Start ()
{
       RenderSettings.skybox.Lerp(skyBox, mat, 0.5f);  //Here assaying mat matiral as default .
}

// Update is called once per frame
void Update ()
{
        a = (Time.time *4) % 360;

        transform.eulerAngles = new Vector3(transform.rotation.x + a , transform.rotation.y, transform.rotation.z);

      
        if(a > 25 && a < 150 )
        {
           //Changing default to day matiral skybox.
            RenderSettings.skybox.Lerp(skyBox,day,0.5f * Time.deltaTime); 
        }
         
       else if (a > 150 && a < 185)
        {
            //Changing day matiral to mat matiral
            RenderSettings.skybox.Lerp(skyBox,mat,0.5f*Time.deltaTime);
        }
}

}

Hope that it will help you!!!

@Tarikm I just made a video about this because a lot of people are saying it’s not possible to do in script but it definitely is!

I hope this video is helpful to people!