Good morning, I'm doing a quiz game, has 6 questions each topic. I wanted to make the questions random (without repeater as well) and just give the final grade after I've done the 6 questions.
I tried with Random.Range, but it did not work because sometimes I only ran about 2, 3 or 1 questions and went to note screen soon, I saw some topics about making a list Shuffle also tried but the Shuffle did not appear in my script and much minus the .Count command so I do not know if it would work.
can anybody help me? Well, I have little knowledge and I do not know how to use Shuffle correctly. If they could talk in detail or send the corrected script I would be very grateful. Thanks in advance for your attention and understanding, and I apologize for any spelling mistakes I'm Brazilian and I used google translator to translate that message.
Here's my complete script that I use for questions and answers.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class responder : MonoBehaviour {
private 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 alternativas A
public string[] alternativaB; //armazena todas as alternativas B
public string[] alternativaC; //armazena todas as alternativas C
public string[] alternativaD; //armazena todas as alternativas D
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; /// se fosse 20 questões aqui seria 19
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); //calcula a media com base no percentual de acerto
notaFinal = Mathf.RoundToInt(media); //calcula a nota para o proximo inteiro, segundo a regra da matematica
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");
}
}
}
}