0

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

Edric
  • 24,639
  • 13
  • 81
  • 91
Tarik Mokafih
  • 1,247
  • 7
  • 19
  • 38
  • 1
    Do you call it inside the `Update()`? – Dinal24 Jan 22 '15 at 01:07
  • 1
    You should copy-paste exact script -- the example code given doesn't look like it would compile, because of capitalization errors. Aside from that, you usually don't want a material to lerp against itself (provide two materials, instead). Your time calculation looks a bit strange. What is the value of `smooth`? – rutter Jan 22 '15 at 01:09

0 Answers0