Also habe ich 10 Fragen, so dass, wenn das Spiel beginnt, beispielsweise die Ausgangsfrage ist „4 von 10“ dann, wenn die nächsten Frage zu zufällig ist „10 von 10“ Das Spiel endet. was ich will, ist zufällig die 10 Fragen:Unity 3D-Quiz Spiel zufällige Fragen
private int idMode;
public Text question;
public Text answerA;
public Text answerB;
public Text answerC;
public Text answerD;
public Text infoAnswer;
public Text stat;
public string[] questions;
public string[] alternativeA;
public string[] alternativeB;
public string[] alternativeC;
public string[] alternativeD;
public string[] correct;
private int idQuestion;
private float points;
private float fact;
private float average;
private int results;
void Start() {
idMode = PlayerPrefs.GetInt ("idMode");
idQuestion = 0;
fact = questions.Length;
question.text = questions [idQuestion];
answerA.text = alternativeA [idQuestion];
answerB.text = alternativeB [idQuestion];
answerC.text = alternativeC [idQuestion];
answerD.text = alternativeD [idQuestion];
infoAnswer.text = (idQuestion + 1).ToString() + " of " + fact.ToString() + "";
}
public void answer(string alternative)
{
if (alternative == "A") {
if (alternativeA [idQuestion] == correct [idQuestion]) {
points += 1;
} else {
}
}
if (alternative == "B") {
if (alternativeB [idQuestion] == correct [idQuestion]) {
points += 1;
} else {
}
}
if (alternative == "C") {
if (alternativeC [idQuestion] == correct [idQuestion]) {
points += 1;
} else {
}
}
if (alternative == "D") {
if (alternativeD [idQuestion] == correct [idQuestion]) {
points += 1;
} else {
}
}
nextQuestion();
}
void nextQuestion()
{
idQuestion += Random.Range(0,10);
if(idQuestion <= (fact-1))
{
question.text = questions [idQuestion];
answerA.text = alternativeA [idQuestion];
answerB.text = alternativeB [idQuestion];
answerC.text = alternativeC [idQuestion];
answerD.text = alternativeD [idQuestion];
stat.text = " Correct: " + points.ToString() + "";
infoAnswer.text = (idQuestion + 1).ToString() + " of " + fact.ToString() + "";
}
else
{
average = 10 * (points/fact);
results = Mathf.RoundToInt (average);
if (results > PlayerPrefs.GetInt ("results" + idMode.ToString())) {
PlayerPrefs.SetInt ("results" + idMode.ToString(), results);
PlayerPrefs.SetInt ("points" + idMode.ToString(), (int)points);
}
PlayerPrefs.SetInt ("resultsTemp" + idMode.ToString(), results);
PlayerPrefs.SetInt ("pointsTemp" + idMode.ToString(), (int)points);
Application.LoadLevel("results");
}
}
}
danke aber muss ich wirklich meine Datenstruktur ändern? keine anderen Möglichkeiten? – Magillanica
Es gibt andere Möglichkeiten, aber die einfachste Möglichkeit wäre, die Datenstruktur zu ändern. Eine andere Möglichkeit ist ein Array von '' '' '' '' '' '' '' '' '' '' '' ''' 'questionMapper' 'zu erstellen und diese dann zu mischen. Dann machst du so etwas wie 'questions [questionMapper [idQuestion]]'. –
Sie sollten die neue Datenstruktur zwar versuchen, aber Sie sollten den Text trotzdem in den Editor einfügen können. Siehe auch mein neustes Update, ich habe vergessen, 'public' auf die Mitglieder in der 'Question'-Klasse zu setzen. –