C#C
C#3y ago
Ramune

❔ Select next/previous item from a list when function called

So I have a list of colors, I want to check if the current color is equal to an array item, find the position of that item in the array, then set it to the next item in the array.

Basically a rainbow loop, so it returns red on first run, green on second run, blue on third run, red on fourth run

        public Color GetRandomColor()
        {
            Color current = light.color;

            List<Color> colors = new List<Color>
            {
                Color.red,
                Color.green,
                Color.blue,
            };

            return newColor;
        }


newColor is not yet defined but will be defined as the resulting next color in the array
Was this page helpful?