I'm just trying to make an observer pattern program one object randomly changes color and causes a group of other objects to change the same color, but I wanted them to gradually change over 5 seconds. I'm trying lerp, but it just instantly swaps colors. I think it maybe has something to do with the lerp's starting color, because the main object is constantly shifting colors and new colors become old colors. So I need to think of how choose a starting color for the lerp. I'm not sure if this has to do with my the lerp isn't working, but it's what I'm considering. If anyone else has any suggestions, I would appreciate it. Thank you.
public class Subject : MonoBehaviour {
public float timer = 0.0f;
public GameObject[] observers;
float t = 0;
Color oldColor;
void Update () {
t += Time.deltaTime / 5.0f;
timer += Time.deltaTime;
if (timer >= 10f) {
Color newColor = new Color(Random.value, Random.value, Random.value, 1.0f);
GetComponent<Renderer>().material.color = newColor;
for (int i = 0; i < observers.Length; i++) {
observers[i].GetComponent<Renderer>().material.color = Color.Lerp(oldColor, newColor, t);
}
newColor=oldColor
timer = 0;
}
}
}