Can't figure out how to make my game verify my answer (Simon game).

I updated this code and now the game is working but I keep getting this error : Argument is out of range. I know kind of why its happening but i can’t figure out how to fix it.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Simon : MonoBehaviour 
{

    public List<int> colorChain = new List<int>();
    public List<int> playerColorChain = new List<int>();
    public bool myTurn = false;
    private int numberOfColor = 0;
    public bool firstTime = true;
    public bool picking = false;
	
	void OnGUI()
    {
        GUI.color = Color.green;
        if(GUI.Button(new Rect(Screen.width / 2 - (Screen.width / 2), Screen.height / 2 - (Screen.height / 2), Screen.width / 2, Screen.height / 2), "Green"))
        {
            if (myTurn && picking)
            {
                playerColorChain.Add(1);
                picking = false;
            }
        }

        GUI.color = Color.red;
        if(GUI.Button(new Rect(Screen.width / 2, Screen.height / 2 - (Screen.height / 2), Screen.width / 2, Screen.height / 2), "Red"))
        {
            if (myTurn && picking)
            {
                playerColorChain.Add(2);
                picking = false;
            }
        }

        GUI.color = Color.blue;
        if (GUI.Button(new Rect(Screen.width / 2 - (Screen.width / 2), Screen.height / 2, Screen.width / 2, Screen.height / 2), "Blue"))
        {
            if (myTurn && picking)
            {
                playerColorChain.Add(3);
                picking = false;
            }
        }

        GUI.color = Color.yellow;
        if (GUI.Button(new Rect(Screen.width / 2, Screen.height / 2, Screen.width / 2, Screen.height / 2), "Yellow"))
        {
            if (myTurn && picking)
            {
                playerColorChain.Add(4);
                picking = false;
            }
        }
    }

	void Update () 
    {
        if(!myTurn && firstTime && !picking)
        {
            RandomColourGen();
        }

        SequenceVerification();
	}

    void RandomColourGen()
    {
        numberOfColor++;

        if (colorChain.Count < numberOfColor)
        {
            colorChain.Add(Random.Range(1, 5));
        }

        firstTime = false;
        picking = true;
        myTurn = true;
    }

    void SequenceVerification()
    {
        if (myTurn)
        {
            for (int i = 0; i < colorChain.Count; i++)
            {
                StartCoroutine("WaitForInput");

                //error happening here
                int color = playerColorChain*;*

if (color == colorChain*)*
{
picking = true;
continue;
}
else
GameOver();
}

playerColorChain.Clear();

firstTime = true;
picking = false;
myTurn = false;
}
}

void GameOver()
{
firstTime = false;
myTurn = false;
picking = false;
Debug.Log(“GameOver”);
Application.Quit();
}

IEnumerator WaitForInput()
{
yield return StartCoroutine(“InputVerification”);
}

IEnumerator InputVerification()
{
while(picking)
{
yield return null;
}
}
}

I’ll suggest some pseudo-code:

  1. Keep a list of the correct answers.
  2. Let X be a counter, starting from 0.
  3. When the player enters a new input, check if it matches the Xth correct answer.
  4. If it did match, increase X by one. If you win, do that. If not, go back to step 3.
  5. If it didn’t match, the player failed.

At step 4, you’ll need to check if the player won (X is greater than or equal to the number of correct guesses required).

If you reach step 5, the player has lost and you can reset the game.

We don’t really need to keep track of all the player’s guesses – either they’re all correct thus far, so they match the official list, or the most recent one is incorrect, so the player loses.