I'm doing a quiz game I need help. How can I make an array (called random questions) to exit and return to the same are not repeated.
using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using System.Collections;
public class responder : MonoBehaviour {
public int idTema;
public Text pergunta;
public Text respostaA;
public Text respostaB;
public Text respostaC;
public Text respostaD;
public Text infoRespostas;
public string[] perguntas; // armazena todas as perguntas.
public string[] alternativaA; // armazena todas as perguntasA.
public string[] alternativaB; // armazena todas as perguntasB.
public string[] alternativaC; // armazena todas as perguntasC.
public string[] alternativaD; // armazena todas as perguntasD.
public string[] corretas; // armazena todas as alternativas corretas.
private int idPergunta;
private float acertos;
private float questoes;
private float media;
private int notaFinal;
// Use this for initialization
void Start () {
idTema = PlayerPrefs.GetInt ("idTema");
idPergunta = 0;
questoes = perguntas.Length;
pergunta.text = perguntas[idPergunta];
respostaA.text = alternativaA[idPergunta];
respostaB.text = alternativaB[idPergunta];
respostaC.text = alternativaC[idPergunta];
respostaD.text = alternativaD[idPergunta];
infoRespostas.text = " Respondendo " + (idPergunta + 1).ToString () + " de " + questoes.ToString () + " perguntas! ";
}
public void resposta(string alternativa)
{
if(alternativa == "A")
{
if (alternativaA[idPergunta] == corretas [idPergunta])
{
acertos += 1;
}
}
else if(alternativa == "B")
{
if (alternativaB [idPergunta] == corretas [idPergunta])
{
acertos += 1;
}
}
else if(alternativa == "C")
{
if (alternativaC [idPergunta] == corretas [idPergunta])
{
acertos += 1;
}
}
else if(alternativa == "D")
{
if (alternativaD [idPergunta] == corretas [idPergunta])
{
acertos += 1;
}
}
proximaPergunta();
}
void proximaPergunta()
{
idPergunta += 1;
if (idPergunta <= (questoes - 1))
{
pergunta.text = perguntas [idPergunta];
respostaA.text = alternativaA [idPergunta];
respostaB.text = alternativaB [idPergunta];
respostaC.text = alternativaC [idPergunta];
respostaD.text = alternativaD [idPergunta];
infoRespostas.text = " respondendo " + (idPergunta + 1).ToString () + " de " + questoes.ToString () + " perguntas! ";
}
else
{
media = 10 * (acertos / questoes);
notaFinal = Mathf.RoundToInt (media);
if (notaFinal > PlayerPrefs.GetInt ("notaFinal" + idTema.ToString ())) {
PlayerPrefs.SetInt ("notaFinal" + idTema.ToString (), notaFinal);
PlayerPrefs.SetInt ("acertos" + idTema.ToString (), (int)acertos);
}
PlayerPrefs.SetInt ("notaFinalTemp" + idTema.ToString (), notaFinal);
PlayerPrefs.SetInt ("acertosTemp" + idTema.ToString (), (int)acertos);
SceneManager.LoadScene ("notaFinal" + idTema.ToString ());
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Is it possible to have 2 references in an array? 1 Answer
Is it possible to store one dimension of a 2d array into a 1d array? 0 Answers
How to edit Properties of a ScriptableObject asset, specificly arrays/lists 0 Answers
How to get text from array or in bool? 1 Answer
How to compare a position of an object within an array 1 Answer