![見出し画像](https://assets.st-note.com/production/uploads/images/138178396/rectangle_large_type_2_c7b6504d1608ecbd8be79526e3cb9281.png?width=1200)
Photo by
inagakijunya
Unity List って何?
この動画で、以下のようなコードが出てきました。
public List<QuestionAndAnswers> QnA;
public GameObject[] options;
public int currentQuestion;
public Text QuestionTxt;
public void Start()
{
generateQuestion();
}
public void correct()
{
QnA.RemoveAt(currentQuestion);
generateQuestion();
}
void SetAnswers()
{
for (int i = 0; i < options.Length; i++)
{
options[i].GetComponent<AnswerScript>().isCorrect = false;
options[i].transform.GetChild(0).GetComponent<Text>().text = QnA[currentQuestion].Answers[i];
if (QnA[currentQuestion].CorrectAnswer == i+1)
{
options[i].GetComponent<AnswerScript>().isCorrect = true;
}
}
}
void generateQuestion()
{
if (QnA.Count > 0)
{
currentQuestion = Random.Range(0, QnA.Count);
QuestionTxt.text = QnA[currentQuestion].Question;
SetAnswers();
}
else
{
Debug.Log("Out of Questions");
}
}
この中で、List がすごい便利でした。
今は仕組みが分からないですが、今度勉強して、List まとめたいと思います。