Так я получил 10 вопросов, поэтому, когда начинается игра, например, исходный вопрос: «4 из 10», то, если следующий вопрос случайным «10 из 10» игра заканчивается. то, что я хочу, чтобы случайно 10 вопросов:Unity 3D Quiz игра Случайные вопросы
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");
}
}
}
спасибо, но мне действительно нужно изменить свою структуру данных? нет других путей? – Magillanica
Существуют и другие способы, но самым простым способом его сохранения было бы изменить структуру данных. Другой вариант - создать массив 'int', отсчитывающий от 0, называемый 'questionMapper', и перетасовать его. Затем вы делаете что-то вроде 'questions [questionMapper [idQuestion]]'. –
Вы должны попробовать новую структуру данных, хотя вы все равно сможете поместить текст в редактор. Также см. Мое последнее обновление, я забыл поставить 'public' в члены класса' Question'. –