How to give an Array for Sprite Renderer

Hello,

I have 5 sprite materials. I want to give all of these into an array. Below I have posted code for single Sprite Renderer, but I am not able to give for an array of sprites. What needs to be changed?

public SpriteRenderer rend;

void Start()
{
rend.enabled = false;
Start Coroutine(DirectionFade());
}

IEnumerator DirectionFade()
    {
        rend.enabled = true;
        yield return new WaitForSeconds(0.5f);
        for (float f = 1f; f >= -0.05f; f -= 0.05f)
            {

                Color c = rend.material.color;
                c.a = f;
                rend.material.color = c;
                yield return new WaitForSeconds(0.05f);

            }
}

Untested but this should do it. I also cached your WaitForSeconds to cut down on the overhead of creating it new each loop cycle.

    public SpriteRenderer [] rend;
    
    void Start()
    {
    for (int i = 0; i < rend.Length; i++)
    rend [i].enabled = false;
    StartCoroutine(DirectionFade());
    }
    
    IEnumerator DirectionFade()
        {
            for (int i = 0; i < rend.Length; i++) {
                rend [i].enabled = true;
            }
            yield return new WaitForSeconds(0.5f);
            WaitForSeconds point05SecondWait = new WaitForSeconds (0.05f);
            for (float f = 1f; f >= -0.05f; f -= 0.05f)
            {
                for (int i = 0; i < rend.Length; i++) {
                    Color c = rend [i].material.color;
                    c.a = f;
                    rend [i].material.color = c;
                }
                yield return point05SecondWait;
    
            }
    }

Thank you for your input. I recently tried the same thing as you described, but unfortunately ‘‘material’’ does not take in array values. Hence I removed the material and just kept “rend*.color”, and it worked. The material didn’t make a difference.*