I am trying to add a list inside a list. But I wasn't able to retrieve the items from the sub list. There is no error, but no data was retrieved from the sub list. Please focus on GenerateClue() I think the error is there.
When I'm trying to access the data using clueList[0][0], There is no data
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public class TrainingMode : MonoBehaviour {
private List<int> answerKey;
private List<int> clue;
private List<List<int>> clueList;
private int correct;
private int wellPlaced;
public Text answerKeyText;
System.Random random = new System.Random();
void Start () {
answerKey = new List<int>();
clue = new List<int>();
clueList = new List<List<int>>();
GenerateAnswerKey();
GenerateClue();
//CheckCorrectAndWellPlaced();
answerKeyText.GetComponent<Text>().text = answerKey[0] + " "+ answerKey[1] + " "+ answerKey[2];
foreach (List<int> arrClue in clueList)
{
foreach (int item in arrClue)
{
Debug.Log(item);
}
}
}
private void GenerateClue()
{
//Generate clue
for (int j = 0; j <= 5; j++)
{
for (int i = 0; i <= 2; i++)
{
int randomNumber = random.Next(0, 9);
if (clue.Contains(randomNumber))
{
i--;
}
else
{
clue.Add(randomNumber);
}
if (clue.Count == 3)
{
clueList.Add(clue);
clue.Clear();
}
}
}
}
private void CheckCorrectAndWellPlaced()
{
correct = 0;
wellPlaced = 0;
//Check for correct and wellplaced numbers
for (int i = 0; i <= 2; i++)
{
if (answerKey.Contains(clue[i]))
{
correct++;
}
if (clue[i] == answerKey[i])
{
wellPlaced++;
}
}
}
private void GenerateAnswerKey() {
//Generate answerkey
for (int i = 0; i <= 2; i++)
{
int randomNumber = random.Next(0, 9);
if (answerKey.Contains(randomNumber))
{
i--;
}
else
{
answerKey.Add(randomNumber);
}
}
}
}