Is there an easier way to do this?

Hello,

I am making a scene with int 1 and int 2 as possible answers, to questions I’ve asked in a previous scene.
Explanation of one of the answers gameobjects

  1. Created the gameobject (that consists of UI images) with two possible answers - 1 and 2. They are integers.
  2. Created 2 gameobjects (consits of UI image of a tick) and set them as un-active. Attached them to the parent gameobject(the answers).

If the player answers with the first answer he sets the playerprefs to interger 1. And if he answers with the second answer he sets the playerprefs to integer 2.

Here is the code, it’s easier to understand form it:

using UnityEngine;
using System.Collections;

public class History : MonoBehaviour {

public GameObject t_1_A;
	public GameObject t_1_B; 
	public GameObject t_2_A;
	public GameObject t_2_B;
	public GameObject t_3_A;
	public GameObject t_3_B; // ----------> these are the answers(ticks)
	public GameObject t_4_A;
	public GameObject t_4_B;
	public GameObject t_5_A;
	public GameObject t_5_B;

    int question1;
	int question2;
	int question3; //from here we set int to  get the playerprefs
	int question4;
	int question5;

       void Start () {
		
		question1 = PlayerPrefs.GetInt("Question1");
		question2 = PlayerPrefs.GetInt("Question2");
		question3 = PlayerPrefs.GetInt("Question3"); // we get the playerprefs
		question4 = PlayerPrefs.GetInt("Question4");
		question5 = PlayerPrefs.GetInt("Question5");


             if(question1 == 1){
			t_1_A.SetActive(true);
			t_1_B.SetActive(false);

		}
		else if(question1 == 2){
			t_1_A.SetActive(false);
			t_1_B.SetActive(true);
		}

		if(question2 == 1){
			t_2_A.SetActive(true);
			t_2_B.SetActive(false);
		}
		else if(question2 == 2){
			t_2_A.SetActive(false);
			t_2_B.SetActive(true);
		}
		if(question3 == 1){
			t_3_A.SetActive(true);
			t_3_B.SetActive(false);
		}
		else if(question3 == 2){
			t_3_A.SetActive(false);
			t_3_B.SetActive(true);
		}
		if(question4 == 1){
			t_4_A.SetActive(true);
			t_4_B.SetActive(false);
		}
		else if(question4 == 2){
			t_4_A.SetActive(false);
			t_4_B.SetActive(true);
		}
		if(question5 == 1){
			t_5_A.SetActive(true);
			t_5_B.SetActive(false);
		}
		else if(question5 == 2){
			t_5_A.SetActive(false);
			t_5_B.SetActive(true);
		}
     }
 }

Now i have to add like 20-30 more answers to questions asked in the first scene of the game, and it gets messy. I would be grateful if some more skillful programmer helps me out here.

Thank you.

If there are always 2 answers to your questions, you can do this:

public class History : MonoBehaviour {

	public GameObject[] answers;
	int[] questions;

	void Start () {
		int newLength = answers.Length/2;
		questions = new int [newLength];
		for (int i = 0; i < newLength; i++) {
			questions  *= PlayerPrefs.GetInt ("Question" + i.ToString());*

if (questions == 1 || questions == 2) {
_ if (questions == 1) {
answers .SetActive (true);
* answers [i + 1].SetActive (false);
} else {
answers .SetActive (false);
answers [i + 1].SetActive (true);
}
}
}
}
}*

Could potentially be optimized further with a mod(ulo)._

If anyone stumbles on this, I am still trying to fix the issue.