0
그래서 난 10 개 질문을 가지고, 그래서 게임이 시작되면, 예는 시작하는 질문은 "10 중 4"그 다음 질문은 "10 10 중"에 임의 경우입니다 게임이 끝납니다. 내가 원하는 무작위로 10 개 질문입니다 :유니티 3D 퀴즈 게임 무작위로 질문
는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
다른 방법이 있지만이를 유지하는 가장 쉬운 방법은 데이터 구조를 변경하는 것입니다. 또 다른 옵션은'questionMapper'라고 불리는 0부터 세 어서'int' 어레이를 만들고 셔플합니다. 그런 다음 질문 [questionMapper [idQuestion]]과 같은 것을합니다. –
새로운 데이터 구조를 시도해야하지만, 여전히 텍스트를 편집기에 넣을 수 있어야합니다. 또한 최신 업데이트를 보았습니다.'Question' 클래스의 멤버에게 public을 넣는 것을 잊었습니다. –