© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
12 replies
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;
        }
        public Color GetRandomColor()
        {
            Color current = light.color;

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

            return newColor;
        }


newColor
newColor
is not yet defined but will be defined as the resulting next color in the array
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Set item to null inside a list
C#CC# / help
4y ago
✅ Combining a List inside of a Select
C#CC# / help
3y ago
random item from a record
C#CC# / help
3y ago