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
- Created the gameobject (that consists of UI images) with two possible answers - 1 and 2. They are integers.
- 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.