How can I go through an array of colliders

I have a script in which i have an array made out of some box colliders and i want each time I have the player enter each one in order to be fine, but if the player skips one collider to throw an error and if it gets to the end of the array, to get back to the top of the array. This is the script I am using:

if (System.Array.IndexOf(TrackCheckpoints.checkpoints, transform) == currentCheckpointIndex)
            rightCheckpoint = true;
        else
            rightCheckpoint = false;

        if (rightCheckpoint == true)
            currentCheckpointIndex++;


        if (currentCheckpointIndex > TrackCheckpoints.checkpointTotalNumber)
            currentCheckpointIndex = 1;

Steps to success:

  • keep an idea of what the next collider should be (such as an integer index into your array)

  • when the player hits a collider in this list:

→ if it is the correct (or next) one, advance the counter
→ if it is the wrong one, reset the counter

  • if at any time the counter is advanced and already on the last one, then wrap back to the first.

This is just basic waypointing. Start with any one of ten billion Youtube tutorials on the idea. They are all going to essentially embody the above core concepts.