using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class GameManager : MonoBehaviour
{
public Questionquestions;
public Buttonbttn;
public Buttonfactbluff;
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 ());
}
}