Hello, I’m trying to use the Color.lerp in my project but it doesnt works and I have no idea why.
using System.Collections;
public class ambient_light : MonoBehaviour {
Color color1;
Color color2;
Color color3;
public float intervalle_trans_color1;
private float m_nextProc_color1;
public float intervalle_trans_color2;
private float m_nextProc_color2;
public float intervalle_trans_color3;
private float m_nextProc_color3;
public bool trans1;
public bool trans2;
public bool trans3;
// Use this for initialization
void Start () {
color1 = new Color(0.25f,0.25f,0.5f);
color2 = new Color(0.25f,0.5f,0.25f);
color3 = new Color(0.5f,0.25f,0.25f);
intervalle_trans_color1 = 6;
intervalle_trans_color2 = 6;
intervalle_trans_color3 = 6;
m_nextProc_color1 = 0;
m_nextProc_color2 = 2;
m_nextProc_color3 = 4;
RenderSettings.ambientLight = color1;
}
// Update is called once per frame
void Update () {
if (trans1 == true) {
RenderSettings.ambientLight = Color.Lerp (color1, color2, Time.time);
}
if (trans2 == true) {
RenderSettings.ambientLight = Color.Lerp (color2, color3, Time.time);
}
if (trans3 == true) {
RenderSettings.ambientLight = Color.Lerp (color3, color1, Time.time);
}
if (Time.timeSinceLevelLoad >= m_nextProc_color1 )
{
m_nextProc_color1 += intervalle_trans_color1;
trans1 = true;
trans3 = false;
}
if (Time.timeSinceLevelLoad >= m_nextProc_color2 )
{
m_nextProc_color2 += intervalle_trans_color2;
trans2 = true;
trans1 = false;
}
if (Time.timeSinceLevelLoad >= m_nextProc_color3 )
{
m_nextProc_color3 += intervalle_trans_color3;
trans3 = true;
trans2 = false;
}
}
}
I’d like to have a loop of smooth lerp between 3 colors on the ambientLight, with this code the color is “lerp” only the first time, after that it just switch from one color to the other without “lerp”.