Hi Unity Answers,
Is there away where I can make the answers to the question below appear in different positions randomly because at the moment every time the question appears on screen the answers are in the same position. Can it be incorporated into my code without many changes?
Someone posted about Lists but I’m not sure how to use them in my code without errors, so could someone show me how to do this please!
All help, suggestions and ideas welcome. Thanks.
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Question1 : MonoBehaviour {
private Rect windowRect = new Rect (500, 100, 400, 200); //Window size
public bool question1;
private int count;
public Text countText;
private bool showTimer = true;
private float Timer = 10f;
public AudioSource countdownAudio;
public AudioSource correctanswerAudio;
public AudioSource wronganswerAudio;
private List<string> answers = new List<string>{"1976", "1986", "1996", "1996"};
void start()
{
count = 0;
SetCountText ();
}
void FixedUpdate(){
if (showTimer == true) {
Timer -= Time.deltaTime;
}
if (Timer <= 0f) {
showTimer = false;
Timer = 10f;
Destroy (this.gameObject);
}
}
void OnGUI(){
{
windowRect = GUI.Window (0, windowRect, WindowFunction, "Ebola Quiz Island"); //window on screen
}
}
void WindowFunction (int windowID)
{
GUI.Label (new Rect (30, 25, 200, 50), " What year did Ebola begin?"); // Question
if (GUI.Button (new Rect (20, 100, 100, 30), "1976")) // Correct Answer
{
AudioSource source = countdownAudio.GetComponent<AudioSource>();
source.mute = true;
correctanswerAudio.Play();
Destroy (this.gameObject);
count = count += 1;
SetCountText ();
}
if (GUI.Button (new Rect (280, 100, 100, 30), "1986")) //Wrong answer
{
AudioSource source = countdownAudio.GetComponent<AudioSource>();
source.mute = !source.mute;
wronganswerAudio.Play();
Destroy (this.gameObject);
}
if (GUI.Button (new Rect (20, 150, 100, 30), "1996")) // wrong answer
{
AudioSource source = countdownAudio.GetComponent<AudioSource>();
source.mute = !source.mute;
wronganswerAudio.Play();
Destroy (this.gameObject);
}
if (GUI.Button (new Rect (280, 150, 100, 30), "1966")) // wrong answer
{
AudioSource source = countdownAudio.GetComponent<AudioSource>();
source.mute = !source.mute;
wronganswerAudio.Play();
Destroy (this.gameObject);
}
if (showTimer == true)
{
GUI.Label (new Rect (300, 25, 200, 50), "Timer: " + Timer.ToString ("F0"));
}
}
void SetCountText()
{
ValuesHolder.answersCount++;
countText.text = "Score: " + ValuesHolder.answersCount.ToString();
}
}