Hi,
I have made a score system which works when you get answer a question correctly.
At the moment the player walks into the cube and a question appears, answer the question correctly then another question appears immediately after.
I have 10 questions and 10 cubes, is there away I can assign 1 question to 1 cube?
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GUIScreen : MonoBehaviour
{
public bool Ebola;
public string Info;
private List<string[]> questions = new List<string[]>();
private List<int> answerOrder = new List<int>(new int[] {1,2,3,4});
private int count;
public Text countText;
void DrawInfo() {
Rect rect = new Rect(500, 100, 400, 200);
Rect close = new Rect(600, 500, 200, 100);
if(GUI.Button(close, "CLICK")) {
Ebola = !Ebola;
}
if (Ebola) {
GUI.Box(rect, Info);
GUI.Label(new Rect(520, 110, 400, 30), questions[0][0]);
if (GUI.Button(new Rect(520, 200, 100, 30), questions[0][answerOrder[0]])) {
HandleAnswer(answerOrder[0]);
}
if (GUI.Button(new Rect(520, 250, 100, 30), questions[0][answerOrder[1]])) {
HandleAnswer(answerOrder[1]);
}
if (GUI.Button(new Rect(780, 200, 100, 30), questions[0][answerOrder[2]])) {
HandleAnswer(answerOrder[2]);
}
if (GUI.Button(new Rect(780, 250, 100, 30), questions[0][answerOrder[3]])) {
HandleAnswer(answerOrder[3]);
}
}
}
private void HandleAnswer(int answer) {
if (answer == 1)
{
count = count + 1;
SetCountText ();
//Destroy (this.gameObject);
//handle correct answer
NextQuestion();
}
else {
//Handle wrong answer
//Destroy (this.gameObject);
}
}
void SetCountText ()
{
countText.text = "Score: " + count.ToString ();
}
void OnGUI() {
if(questions.Count > 0) {
DrawInfo();
}
}
void Start() {
count = 0;
SetCountText ();
// String order: question, correct, wrong, wrong, wrong
questions.Add(new string[] { "What year did Ebola begin?", "1976", "1986", "1996", "1966" });// Question 1
NextQuestion();
questions.Add(new string[] { "What is the Ebola virus named after?", "A river", " A farm", "A tree", "A city" }); // Question 2
questions.Add(new string[] { "Which of these can pass along the ebola virus?", "Tears", "Dandruff", "Fingernails", "Soap" }); // Question 3
questions.Add(new string[] { "Ebola is contagious only when someone has symptoms?", "True", "False", "", "" }); // Question 4
questions.Add(new string[] { "Scientists think Ebola first came from?", "Bats", "Dogs", "Gorillas", "Mosquitoes" }); // Question 5
questions.Add(new string[] { "Men who recover from Ebola should do this for 3 months?", "Wear condoms", "Test blood sugar", "Use private toilets", "Shower twice a day" }); // Question 6
questions.Add(new string[] { "Which is the bigger threat: Ebola or the flu?", "Flu", "Ebola", "", "" }); // Question 7
questions.Add(new string[] { "How many strains of the Ebola virus are there?", "Five", "One", "Three", "More than 100" }); // Question 8
questions.Add(new string[] { "How long can the Ebola virus live on something outside the body?", "Up to 6 days", "Up to 6 hours", "Up to 6 minutes", "Up to 6 months" }); // Question 9
questions.Add(new string[] { "How many proven treatments are there for Ebola?", "None", "One", "Two", "Three" }); // Question 10
Shuffle(questions);
Shuffle(answerOrder);
}
void NextQuestion() {
questions.RemoveAt(0);
Shuffle(answerOrder);
}
static readonly System.Random rng = new System.Random();
public static void Shuffle<T>(IList<T> list) {
int n = list.Count;
while(n > 1) {
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
}