2
I wanted to make the questions were random but not repeated running the 6 questions that make up each theme of my QUIZ-style game, if they know an easy method for my problem.
I tried several researches and did not get anything maybe because I did not know apply the most advanced knowledge of the staff, please if you can explain in detail I would be very grateful because I am beginner. Thanks for your attention and understanding. Follow my script I use for answers.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
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 AudioSource m_Audiosource;
public string[] perguntas; //alterei aqui 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;
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;
m_Audiosource.Play ();
}
}
else if (alternativa == "B") {
if (alternativaB [idPergunta] == corretas [idPergunta])
{
acertos += 1;
m_Audiosource.Play ();
}
}
else if (alternativa == "C") {
if (alternativaC [idPergunta] == corretas [idPergunta])
{
acertos += 1;
m_Audiosource.Play ();
}
}
else if (alternativa == "D") {
if (alternativaD [idPergunta] == corretas [idPergunta])
{
acertos += 1;
m_Audiosource.Play ();
}
}
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 = 6 * (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");
}
}
}
}
Thank you for clarifying :)
– Rayllander