Combining 3 color transitions?

I’m trying to find a way to transition between three colors on one light.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RTB : MonoBehaviour {

    public float duration = 1.0F;
    public Color color0 = Color.red;
    public Color color1 = Color.blue;
    public Color color2 = Color.green;
    public Light lit;
    void Start()
    {
        lit = GetComponent<Light>();
    }
    void Update()
    {
        float t = Mathf.PingPong(Time.time, duration) / duration;
        lit.color = Color.Lerp(color0, color1, t);
    }
}

I was using Lerp before, but instead of just using “color0, color1, t” I need “color0, color1, color2, t”
I don’t know what to use to add all three.

Here you go:

//Multi Color Lerp
int index = 0;
public Color[] colors;
float t;

void Update()
{
    t += Time.deltaTime;                                                          
    Color c = Color.Lerp(colors[index], colors[(index + 1) % colors.Length], t);  
    if (t >= 1)                                                                   
    {
        index = (index + 1) % colors.Length;                                      
        t = 0;                                                                    
    }
    lit.color = c;                                     
}

Time between each frame is added each frame for a smooth, uniform transition. It then
lerps between current colour and next colour. If it’s at last index it instead lerps towards first colour.

When the transition is finished it increments the index and loops if it would be past the last value.

I’m sure there are better ways to do this. You might be able to make it cheaper using coroutines and inputting a transition time.