- Home /
what would be the if statement if the previous question loaded is repeated or equal to the same..
using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System.Collections; using System.Collections.Generic; using System.Linq;
public class GameManager : MonoBehaviour { public Question[]questions; public Button[]bttn; public Button[]factbluff; public int life=5;
private static List<Question>unansweredQuestions;
private Question currentQuestion;
public GameObject GameQuestionHolder;
public GameObject GameAnswerHolder;
public GameObject GameAnswer1Holder;
public GameObject GameAnswer2Holder;
public GameObject GamePauseHolder;
public GameObject IncorrectAnswerHolder;
public GameObject CorrectAnswerHolder;
[SerializeField]
private Text questiontext;
[SerializeField]
private Text answertext;
[SerializeField]
private Text answertext1;
[SerializeField]
private Text answertext2;
[SerializeField]
private Text lifenum;
[SerializeField]
private float timeBetweenQuestions = 1f;
[SerializeField]
private Animator animator;
void Start()
{
if (unansweredQuestions == null || unansweredQuestions.Count==0)
{
unansweredQuestions = questions.ToList<Question>();
}
SetCurrentQuestion ();
}
void SetCurrentQuestion()
{
int randomQuestionIndex = Random.Range (0, unansweredQuestions.Count);
currentQuestion = unansweredQuestions [randomQuestionIndex];
questiontext.text=currentQuestion.questionText;
}
IEnumerator TransitionToNextQuestion()
{
unansweredQuestions.Remove (currentQuestion);
yield return new WaitForSeconds (timeBetweenQuestions);
SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);
}
public void GamePause()
{
GamePauseHolder.SetActive (true);
GameQuestionHolder.SetActive (false);
GameAnswerHolder.SetActive (false);
GameAnswer1Holder.SetActive (false);
GameAnswer2Holder.SetActive (false);
IncorrectAnswerHolder.SetActive (false);
CorrectAnswerHolder.SetActive (false);
}
public void GameQuestion()
{
GameQuestionHolder.SetActive (true);
GameAnswerHolder.SetActive (false);
GameAnswer1Holder.SetActive (false);
GameAnswer2Holder.SetActive (false);
GamePauseHolder.SetActive (false);
IncorrectAnswerHolder.SetActive (false);
CorrectAnswerHolder.SetActive (false);
}
public void GameMenu()
{
SceneManager.LoadScene ("GameMenu");
}
public void SelectBluffer()
{
GameAnswerHolder.SetActive (true);
GameQuestionHolder.SetActive (false);
GameAnswer1Holder.SetActive (false);
GameAnswer2Holder.SetActive (false);
GamePauseHolder.SetActive (false);
IncorrectAnswerHolder.SetActive (false);
CorrectAnswerHolder.SetActive (false);
answertext.text = currentQuestion.answers [0].answerText;
}
public void SelectBluffer1 ()
{
GameAnswer1Holder.SetActive(true);
GameQuestionHolder.SetActive (false);
GameAnswerHolder.SetActive (false);
GameAnswer2Holder.SetActive (false);
GamePauseHolder.SetActive (false);
IncorrectAnswerHolder.SetActive (false);
CorrectAnswerHolder.SetActive (false);
answertext1.text = currentQuestion.answers [1].answerText;
}
public void SelectBluffer2()
{
GameAnswer2Holder.SetActive (true);
GameQuestionHolder.SetActive (false);
GameAnswerHolder.SetActive (false);
GameAnswer1Holder.SetActive (false);
GamePauseHolder.SetActive (false);
IncorrectAnswerHolder.SetActive (false);
CorrectAnswerHolder.SetActive (false);
answertext2.text = currentQuestion.answers [2].answerText;
}
public void Fact()
{
if (currentQuestion.answers [0].isTrue )
{
CorrectAnswerHolder.SetActive (true);
lifenum.text = "Life : " + life.ToString ();
}
else
{
IncorrectAnswerHolder.SetActive (true);
}
StartCoroutine (TransitionToNextQuestion ());
}
public void Bluff()
{
if (!currentQuestion.answers [0].isTrue)
{
CorrectAnswerHolder.SetActive (true);
}
else
{
IncorrectAnswerHolder.SetActive (true);
}
StartCoroutine (TransitionToNextQuestion ());
}
public void Fact1()
{
if (currentQuestion.answers [1].isTrue )
{
CorrectAnswerHolder.SetActive (true);
}
else
{
IncorrectAnswerHolder.SetActive (true);
}
StartCoroutine (TransitionToNextQuestion ());
}
public void Bluff1()
{
if (!currentQuestion.answers [1].isTrue)
{
CorrectAnswerHolder.SetActive (true);
}
else
{
IncorrectAnswerHolder.SetActive (true);
}
StartCoroutine (TransitionToNextQuestion ());
}
public void Fact2()
{
if (currentQuestion.answers [2].isTrue )
{
CorrectAnswerHolder.SetActive (true);
}
else
{
IncorrectAnswerHolder.SetActive (true);
}
StartCoroutine (TransitionToNextQuestion ());
}
public void Bluff2()
{
if (!currentQuestion.answers [2].isTrue)
{
CorrectAnswerHolder.SetActive (true);
}
else
{
IncorrectAnswerHolder.SetActive (true);
}
StartCoroutine (TransitionToNextQuestion ());
}
}
To be honest, I didn't get your question but i can sense that that's not very nice coding... Why dont you create 1 Fact and one Bluff with loops or checks the index of the question and uses it.
I do agree with the both of you.. what should be the for loop code for the buttons?
Answer by ShadyProductions · Mar 22, 2017 at 09:07 AM
I do agree with Matt, this could be done alot cleaner. But to answer your question, you will need to keep 2 variables
private Question currentQuestion;
private Question previousQuestion;
if (currentQuestion == previousQuestion) {
//do whatever
}
I do agree with the both of you.. what should be the for loop code for the buttons?
Your answer
Follow this Question
Related Questions
if Statement Help Increment Value 2 Answers
(if statement) is acting weird 1 Answer
TBG,If,While 1 Answer
Why is this if-statement returning true? 1 Answer
Check if gravity is inverted 1 Answer