How to lerp through colors for a sprite?

I’m trying to make my background, which is a sprite, smoothly change through the colors of the rainbow. I tried using GetComponent().color to just set one color but I can’t even get that working. Can someone help me figure out what code is needed to iterate through colors smoothly?

I don’t know if this will help you or not, but here’s some code that kind of does what you want. It should work if you add it to the sprite. This example just lerps from blue to orange, but you can add as many colors to the list as you want.

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

public class ColorShift : MonoBehaviour
{
    SpriteRenderer sRenderer;
    float lerpTime = 4.0f;
    List<Color> colors;

	void Start ()
    {
        colors = new List<Color>() { Color.blue, new Color(1, .502f, 0) };
        sRenderer = GetComponent<SpriteRenderer>();
    }
	
	void Update ()
    {
        if(Input.GetKeyUp(KeyCode.S))
        {
            StartCoroutine(ColorLerp());
        }
	}

    IEnumerator ColorLerp()
    {
        if (colors.Count >= 2)
        {
            for (int i = 1; i < colors.Count; i++)
            {          
                float startTime = Time.time;
                float percentageComplete = 0;

                while (percentageComplete < 1)
                {
                    float elapsedTime = Time.time - startTime;
                    percentageComplete = elapsedTime / (lerpTime / (colors.Count - 1));
                    sRenderer.color = Color.Lerp(colors[i - 1], colors*, percentageComplete);*

yield return null;
}
}
}
}
}