子供向けの簡単なクイズゲームを作っています。jsonファイルから質問を抽出しています。各質問には 10 秒のタイマーがあり、ボタンを押すと次の質問が表示されます。私が直面している問題は、「yield return waitforseconds()」を制御する方法を理解できないように見えることです。私は複数のアプローチを試しましたが、どれもうまくいかないようです。しばらく探していますが、何も見つかりません。私は明日締め切りがあります、私は本当に助けが必要です.
//this is my question changing method
IEnumerator QuestionRoutin(Course c, int n)
{
while (qCounter < 3)
{
print(qCounter);
r = UnityEngine.Random.Range(0, 6);
//Question.text = c.Ques_Data[r].Quesion;
//RandomButton(c, r);
//amil = c.Ques_Data[r].Answer;
if(checkq.Count==0)
{
checkq.Add(r);
Question.text = c.Ques_Data[r].Quesion;
RandomButton(c, r);
amil = c.Ques_Data[r].Answer;
}
else if (checkq.Contains(r)==false)
{
checkq.Add(r);
Question.text = c.Ques_Data[r].Quesion;
RandomButton(c, r);
amil = c.Ques_Data[r].Answer;
}
else
{
continue;
}
if (f == true) //f is a global bool
{
f = false;
qCounter++;
//yield return new WaitForSeconds(1.0f);
}
else
{
yield return new WaitForSeconds(10);
qCounter++;
}
}
print("questions are finished");
}
//this a function attach to my buttons
public void CheckAnswer(Text button_txt)
{
//time_1 = 10.0f;
if (button_txt.text == amil)
{
flag = true;
Animator anim = Correct_Panel.GetComponentInChildren<Animator>();
if (anim != null)
{
Correct_Panel.SetActive(true);
bool isRightAnsPressed = anim.GetBool("isRightAnsPressed");
anim.SetBool("isRightAnsPressed", !isRightAnsPressed);
Invoke("disableCorrectPanel", 1.0f);
score_value = score_value + 10;
score.text = "Score: " + score_value;
//have tried all these 3 things
//StartQuestionRoutine(c1, n,true);
//qCounter++;
// flag = true;
}
}
ボタンでコルーチンを呼び出すと、コルーチンが再び再起動すると言われますが、他に何も機能していないようです。ボタンが押されているかどうかにかかわらず、他にどのように機能しますか?私は本当にいくつかの助けを借りることができます。