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;
}
}
}