Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using UnityEngine.EventSystems;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- public class GameManager : MonoBehaviour {
- public Questions[] questions;
- private static List<Questions> unansweredQuestions;
- private Questions currentQuestion;
- [SerializeField]
- private Text factText;
- [SerializeField]
- private Text answerOneText;
- [SerializeField]
- private Text answerTwoText;
- [SerializeField]
- private Text answerThreeText;
- [SerializeField]
- private Text answerFourText;
- [SerializeField]
- private float timeBetweenQuestions = 2f;
- [SerializeField]
- public static int scorePoints;
- [SerializeField]
- private Text scoreText;
- public Button buttonOne;
- public Button buttonTwo;
- public Button buttonThree;
- public Button buttonFour;
- public static bool bolerano;
- public Material good;
- public Material notGood;
- public GameObject goed;
- public GameObject fout;
- public GameObject pos1;
- public GameObject pos2;
- public GameObject pos3;
- public GameObject pos4;
- private bool isFirstTime = true;
- private bool isAnswered = false;
- private GameObject _instance;
- private GameObject _instance2;
- private GameObject _instance3;
- private GameObject _instance4;
- private GameObject _instance5;
- private GameObject _instance6;
- private GameObject _instance7;
- private GameObject _instance8;
- void Start()
- {
- scorePoints = 0;
- UpdateScore();
- if (isFirstTime && (unansweredQuestions == null || unansweredQuestions.Count == 0))
- {
- unansweredQuestions = questions.ToList<Questions>();
- isFirstTime = false;
- }
- SetCurrentQuestion();
- }
- /*
- void Start()
- {
- //if ()
- //{
- unansweredQuestions = questions.ToList<Questions>();
- //}
- if (unansweredQuestions == null || unansweredQuestions.Count == 0)
- {
- SceneManager.LoadScene(0);
- }
- SetCurrentQuestion();
- }*/
- public void AddScore(int newScore)
- {
- scorePoints += newScore;
- UpdateScore();
- }
- void UpdateScore()
- {
- scoreText.text = "Score: " + scorePoints;
- }
- void SetCurrentQuestion()
- {
- if (unansweredQuestions.Count <= 5)
- {
- bolerano = true;
- unansweredQuestions.Clear();
- SceneManager.LoadScene(5);
- }
- int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
- currentQuestion = unansweredQuestions[randomQuestionIndex];
- factText.text = currentQuestion.fact;
- answerOneText.text = currentQuestion.answerOne;
- answerTwoText.text = currentQuestion.answerTwo;
- answerThreeText.text = currentQuestion.answerThree;
- answerFourText.text = currentQuestion.answerFour;
- }
- IEnumerator TransitionToNextQuestion()
- {
- unansweredQuestions.Remove(currentQuestion);
- yield return new WaitForSeconds(timeBetweenQuestions);
- Destroy(_instance);
- Destroy(_instance2);
- Destroy(_instance3);
- Destroy(_instance4);
- Destroy(_instance5);
- Destroy(_instance6);
- Destroy(_instance7);
- Destroy(_instance8);
- isAnswered = false;
- SetCurrentQuestion();
- }
- public void UserSelectOne()
- {
- if (currentQuestion.isOne && !isAnswered)
- {
- AddScore(1);
- cubo1.GetComponent<Renderer>().material = good;
- _instance = (GameObject) Instantiate(goed, pos1.transform.position, goed.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- else
- {
- if (!isAnswered)
- {
- AddScore(-1);
- cubo1.GetComponent<Renderer>().material = notGood;
- _instance2 = (GameObject)Instantiate(fout, pos1.transform.position, fout.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- }
- //StartCoroutine(TransitionToNextQuestion());
- }
- public void UserSelectTwo()
- {
- if (currentQuestion.isTwo && !isAnswered)
- {
- AddScore(1);
- cubo2.GetComponent<Renderer>().material = good;
- _instance3 = (GameObject) Instantiate(goed, pos2.transform.position, goed.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- else
- {
- if (!isAnswered)
- {
- AddScore(-1);
- cubo2.GetComponent<Renderer>().material = notGood;
- _instance4 = (GameObject)Instantiate(fout, pos2.transform.position, fout.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- }
- //StartCoroutine(TransitionToNextQuestion());
- }
- public void UserSelectThree()
- {
- if (currentQuestion.isThree && !isAnswered)
- {
- AddScore(1);
- cubo3.GetComponent<Renderer>().material = good;
- _instance5 = (GameObject)Instantiate(goed, pos3.transform.position, goed.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- else
- {
- if (!isAnswered)
- {
- AddScore(-1);
- cubo3.GetComponent<Renderer>().material = notGood;
- _instance6 = (GameObject)Instantiate(fout, pos3.transform.position, fout.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- }
- //StartCoroutine(TransitionToNextQuestion());
- }
- public void UserSelectFour()
- {
- if (currentQuestion.isFour && !isAnswered)
- {
- AddScore(1);
- cubo4.GetComponent<Renderer>().material = good;
- _instance7 = (GameObject) Instantiate(goed, pos4.transform.position, goed.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- else
- {
- if (!isAnswered)
- {
- AddScore(-1);
- cubo4.GetComponent<Renderer>().material = notGood;
- _instance8 = (GameObject)Instantiate(fout, pos4.transform.position, fout.transform.rotation);
- isAnswered = true;
- StartCoroutine(TransitionToNextQuestion());
- }
- }
- //StartCoroutine(TransitionToNextQuestion());
- }
- public void UserSelectBack()
- {
- SceneManager.LoadScene(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement