Unity 2D. Why is my Sprite invisiblity after running my Script?

Before I post my code, I want to explain what my goal is.
Currently learning, so I hope some good tips and ideas will help me make this work.

An Object should have its colour changed for a certain period of time.
Suppose I have 10 objects and I want to control which kind of colour each object should have,
and also for how long time before it will change to another Color.

I tried it myself, but failed.
As a result, I tried ChatGPT.
I will post the code here.
For whatever reason, I am unable to see my GameObject.

using UnityEngine;

public class ColorChangeController : MonoBehaviour
{
    [System.Serializable]
    public struct ColorDuration
    {
        public Color color;
        public float duration;
    }

    public ColorDuration[] colorDurations;

    private SpriteRenderer spriteRenderer;
    private int currentIndex = 0;

    private void Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        // Start color changing process
        ChangeColor(currentIndex);
    }

    private void ChangeColor(int index)
    {
        ColorDuration currentColorDuration = colorDurations[index];

        // Change color and duration
        spriteRenderer.color = currentColorDuration.color;
        float duration = currentColorDuration.duration;

        // Call ChangeColor method again after the specified duration
        Invoke("NextColor", duration);
    }

    private void NextColor()
    {
        // Move to the next color index
        currentIndex++;

        // Reset index if it exceeds array length
        if (currentIndex >= colorDurations.Length)
        {
            currentIndex = 0;
        }

        // Change color again
        ChangeColor(currentIndex);
    }
}

I haven’t looked at the code yet, maybe that’s the reason. But I remembered one moment with a similar problem associated with fields of the color type and the invisibility of objects.
Perhaps you have the following reason why objects disappear. When there is a field with type color, by default it is black and completely transparent. That is, its alpha has a value of zero. In the inspector, you simply changed the color, but the alpha could still remain at zero. Check the alpha of each color type field.

Don‘t use Invoke but a coroutine if you want to delay execution.
At the very least use nameof(NextColor) instead of a hardcoded string so it doesn‘t break when there is a mismatch eg after renaming the method.

Can‘t see a reason why it wouldn‘t work besides that though, except the alpha thing.

Thanks for your answer.
Lol, why didn’t I think about it, alpha!

Did just added any color and chose whatever I liked, didn’t check for Alpha.
Was sure that Alpha is set to 255 as the default.

Wonder why ChatGPT didn’t ask for Alpha.
Anyway, thanks for the Answer :slight_smile: