私は単純なクイズアプリを作成しており、常に異なる質問を表示したいと思います。それはあなたの質問から明らかではない以前に使用されていたものとは異なる乱数を生成するC#
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using System.Linq;
public class test : MonoBehaviour {
public Text question;
public Text answerA;
public Text answerB;
public Text answerC;
public Text answerD;
public Text answersInfo;
public int themeid;
public string[] questions; //store all questions
public string[] choicesA; //store all choices A
public string[] choicesB; //store all choices B
public string[] choicesC; //store all choices C
public string[] choicesD; //store all choices D
public string[] right; //store all right choices
private int questionid;
private int id;
private bool checkRandom = true;
private float totalRight;
private float totalQuestions;
private float average;
private int finalNote;
List<int> idUsed = new List<int>();
void Start()
{
id = Random.Range(0, 4);
questionid = 0;
totalQuestions = 5;
question.text = questions[id];
answerA.text = choicesA[id];
answerB.text = choicesB[id];
answerC.text = choicesC[id];
answerD.text = choicesD[id];
idUsed.Add(id);
answersInfo.text = "Answering question " + (questionid + 1).ToString() + " out of " + totalQuestions.ToString();
}
public void response(string choice)
{
switch (choice)
{
case "A":
if (choicesA[id] == right[id])
{
totalRight += 1;
}
break;
case "B":
if (choicesB[id] == right[id])
{
totalRight += 1;
}
break;
case "C":
if (choicesC[id] == right[id])
{
totalRight += 1;
}
break;
case "D":
if (choicesD[id] == right[id])
{
totalRight += 1;
}
break;
}
nextQuestion();
}
void nextQuestion()
{
questionid += 1;
if (questionid <= (totalQuestions - 1))
{
totalQuestions = 5;
id = Random.Range(0, 4);
while(checkRandom)
{
if (idUsed.Contains(id))
{
id = Random.Range(0, 4);
}
else
{
idUsed.Add(id);
checkRandom = false;
}
}
question.text = questions[id];
answerA.text = choicesA[id];
answerB.text = choicesB[id];
answerC.text = choicesC[id];
answerD.text = choicesD[id];
answersInfo.text = "Answering question " + (questionid + 1).ToString() + " out of " + totalQuestions.ToString();
}
else
{
average = 10 * (totalRight/totalQuestions);
finalNote = Mathf.RoundToInt(average);
if (finalNote > PlayerPrefs.GetInt("finalNote" + themeid.ToString()))
{
PlayerPrefs.SetInt("finalNote" + themeid.ToString(), finalNote);
PlayerPrefs.SetInt("totalRight" + themeid.ToString(), (int)totalRight);
}
PlayerPrefs.SetInt("finalTempNote" + themeid.ToString(), finalNote);
PlayerPrefs.SetInt("totalRight" + themeid.ToString(), (int)totalRight);
SceneManager.LoadScene("FinalNote");
}
}
あなたは「しかし、うまくいかない」と言います。ビジュアルスタジオでデバッグしましたか?どのような行動は、 "それは動作していないようです"ですか? – PhillipH
@PhillipH私は持っていますが、私はクイズで質問をするためにそれを使用しています。 –