Randomise the position of answers in buttons for question?

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?

All help, suggestions and ideas welcome. Thanks.

alt text

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;


	
	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();
		}


}

Not sure if my syntax is correct, but putting the answers in a list is an option.

// create a list
List<string> answers = new List<string>{"1999","1987","1293","1234"};
    //run a for loop to shuffle the list
    for (int i = 0; i < answers.Count; i++) {
             string temp = answers*;*

int randomIndex = Random.Range(i, answers.Count);
answers = answers[randomIndex];
answers[randomIndex] = temp;
//assign the list elements to the buttons
GUI.Button (new Rect (20, 100, 100, 30), answers[0]);
GUI.Button (new Rect (280, 100, 100, 30), answers[1]);
GUI.Button (new Rect (20, 150, 100, 30), answers[2]);
GUI.Button (new Rect (280, 150, 100, 30), answers[3]);
You could store the correct answer as a separate string and check to see if the button contains the string.
Also, couldnt you remove some of those if statements by using else{}?
heres an edit I did, try it out.

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 answers = new List{“1976”,“1987”,“1493”,“1734”};*
* private string rightAnswer;*

* void Start()*
* {*
* count = 0;*
* SetCountText ();*
* rightAnswer = answers [0];//store right answer*
* for (int i = 0; i < answers.Count; i++) {*
_ string temp = answers ;
* int randomIndex = Random.Range (i, answers.Count); // shuffle list*
answers = answers [randomIndex];
* answers [randomIndex] = temp;*_

* }*
* }*

* 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*
* GUI.Button (new Rect (20, 100, 100, 30), answers[0]);*
* GUI.Button (new Rect (280, 100, 100, 30), answers[1]);*
* GUI.Button (new Rect (20, 150, 100, 30), answers[2]);*
* GUI.Button (new Rect (280, 150, 100, 30), answers[3]);*
* if (GUI.Button (new Rect (20, 100, 100, 30), rightAnswer)) {*
* CorrectAnswerWoo ();*
* SetCountText ();*
* } else if (GUI.Button (new Rect (280, 100, 100, 30), rightAnswer)) {*
* CorrectAnswerWoo ();*
* SetCountText ();*
* } else if (GUI.Button (new Rect (20, 150, 100, 30), rightAnswer)) {*
* CorrectAnswerWoo ();*
* SetCountText ();*
* } else if (GUI.Button (new Rect (280, 150, 100, 30), rightAnswer)) {*
* CorrectAnswerWoo ();*
* SetCountText ();*
* } else {*
* WrongAnswerBoo ();*
* Destroy (this.gameObject);*
* }*
* if (showTimer == true)*
* {*
* GUI.Label (new Rect (300, 25, 200, 50), "Timer: " + Timer.ToString (“F0”));*

* }*

* }*
* void CorrectAnswerWoo(){*
* AudioSource source = countdownAudio.GetComponent ();*
* source.mute = true;*
* correctanswerAudio.Play ();*
* Destroy (this.gameObject);*
* count = count += 1;*

* }*
* void WrongAnswerBoo(){*
* AudioSource source = countdownAudio.GetComponent ();*
* source.mute = !source.mute;*
* wronganswerAudio.Play ();*

* }*
* void SetCountText()*
* {*
* ValuesHolder.answersCount++;*
* countText.text = "Score: " + ValuesHolder.answersCount.ToString();*
* }*

}