- Home /
Question by
neoxdeath02 · Nov 16, 2016 at 03:57 PM ·
how to
i want to make may 20 question randomize plss help its for may baby thesis :D thx
using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System.Collections;
public class responder : MonoBehaviour {
public int idtema;
public Text pergunta; //pergunta means question//
public Text btnA;
public Text btnB;
public Text btnC;
public Text btnD;
public Text inforepostas;
public string[] perguntas;
public string[] alternativeA;
public string[] alternativeB;
public string[] alternativeC;
public string[] alternativeD;
public string[] correct;
private int idPergunta;
private float Answering;
private float question;
private float media;
// Use this for initialization
void Start () {
idPergunta = 0;
question = perguntas.Length;
pergunta.text = perguntas [idPergunta];
btnA.text = alternativeA [idPergunta];
btnB.text = alternativeB [idPergunta];
btnC.text = alternativeC [idPergunta];
btnD.text = alternativeD [idPergunta];
inforepostas.text = " Answering " + (idPergunta + 1).ToString()+ " of " + question.ToString ()+"questions.";
}
public void btn(string alternative)
{
if(alternative == "A")
{
if (alternativeA[idPergunta] == correct [idPergunta]) //EXECUTE A COMMAND FOR ANSWER A
{
Answering += 1;
}
}
else if(alternative == "B")
{
if (alternativeB[idPergunta] == correct [idPergunta])
{
Answering += 1;
}
}
else if(alternative == "C")
{
if (alternativeC[idPergunta] == correct [idPergunta])
{
Answering += 1;
}
}
else if(alternative == "D")
{
if (alternativeD[idPergunta] == correct [idPergunta])
{
Answering += 1;
}
}
idtema = Random.Range (0, 9);
proximaPergunta();
}
void proximaPergunta()
{
idPergunta += 1;
if (idPergunta <= (question - 1)) {
pergunta.text = perguntas [idPergunta];
btnA.text = alternativeA [idPergunta];
btnB.text = alternativeB [idPergunta];
btnC.text = alternativeC [idPergunta];
btnD.text = alternativeD [idPergunta];
inforepostas.text = " Answering " + (idPergunta + 1).ToString () + " of " + question.ToString () + "questions.";
} else
{
SceneManager.LoadScene ("Result1");
}
}
}
Comment
Use idPergunta = Random.Range(0,perguntas.Lenght);. if you want the question to not repeat use a List to hold the id of the already used question and check if the list contains idPergunta before show the question.
Your answer
Follow this Question
Related Questions
how do you make a 3d person or object? 2 Answers
SQLite in Unity 4.x? 0 Answers
how to open probuilder basic 1 Answer
How do i make my player jump from an angle? (Wallrun Jump) 1 Answer
How to make atmospheric dust particles? 4 Answers