Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.01 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.SceneManagement;
  4. using UnityEngine.EventSystems;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8.  
  9. public class GameManager : MonoBehaviour {
  10.  
  11.     public Questions[] questions;
  12.     private static List<Questions> unansweredQuestions;
  13.  
  14.     private Questions currentQuestion;
  15.  
  16.     [SerializeField]
  17.     private Text factText;
  18.  
  19.     [SerializeField]
  20.     private Text answerOneText;
  21.  
  22.     [SerializeField]
  23.     private Text answerTwoText;
  24.  
  25.     [SerializeField]
  26.     private Text answerThreeText;
  27.  
  28.     [SerializeField]
  29.     private Text answerFourText;
  30.  
  31.     [SerializeField]
  32.     private float timeBetweenQuestions = 2f;
  33.  
  34.     [SerializeField]
  35.     public static int scorePoints;
  36.     [SerializeField]
  37.     private Text scoreText;
  38.  
  39.     public Button buttonOne;
  40.     public Button buttonTwo;
  41.     public Button buttonThree;
  42.     public Button buttonFour;
  43.  
  44.     public static bool bolerano;
  45.  
  46.     public Material good;
  47.     public Material notGood;
  48.     public GameObject goed;
  49.     public GameObject fout;
  50.     public GameObject pos1;
  51.     public GameObject pos2;
  52.     public GameObject pos3;
  53.     public GameObject pos4;
  54.     private bool isFirstTime = true;
  55.     private bool isAnswered = false;
  56.     private GameObject _instance;
  57.     private GameObject _instance2;
  58.     private GameObject _instance3;
  59.     private GameObject _instance4;
  60.     private GameObject _instance5;
  61.     private GameObject _instance6;
  62.     private GameObject _instance7;
  63.     private GameObject _instance8;
  64.  
  65.  
  66.     void Start()
  67.     {
  68.         scorePoints = 0;
  69.  
  70.         UpdateScore();
  71.  
  72.         if (isFirstTime && (unansweredQuestions == null || unansweredQuestions.Count == 0))
  73.         {
  74.             unansweredQuestions = questions.ToList<Questions>();
  75.             isFirstTime = false;
  76.         }
  77.  
  78.         SetCurrentQuestion();
  79.     }
  80.    
  81.  
  82.     /*
  83.     void Start()
  84.     {
  85.         //if ()
  86.         //{
  87.             unansweredQuestions = questions.ToList<Questions>();
  88.         //}
  89.  
  90.         if (unansweredQuestions == null || unansweredQuestions.Count == 0)
  91.         {
  92.             SceneManager.LoadScene(0);
  93.         }
  94.        
  95.         SetCurrentQuestion();
  96.     }*/
  97.  
  98.     public void AddScore(int newScore)
  99.     {
  100.         scorePoints += newScore;
  101.         UpdateScore();
  102.     }
  103.  
  104.     void UpdateScore()
  105.     {
  106.         scoreText.text = "Score: " + scorePoints;
  107.     }
  108.  
  109.     void SetCurrentQuestion()
  110.     {
  111.         if (unansweredQuestions.Count <= 5)
  112.         {
  113.             bolerano = true;
  114.             unansweredQuestions.Clear();
  115.             SceneManager.LoadScene(5);
  116.         }
  117.  
  118.         int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
  119.         currentQuestion = unansweredQuestions[randomQuestionIndex];
  120.  
  121.         factText.text = currentQuestion.fact;
  122.         answerOneText.text = currentQuestion.answerOne;
  123.         answerTwoText.text = currentQuestion.answerTwo;
  124.         answerThreeText.text = currentQuestion.answerThree;
  125.         answerFourText.text = currentQuestion.answerFour;
  126.     }
  127.  
  128.     IEnumerator TransitionToNextQuestion()
  129.     {
  130.         unansweredQuestions.Remove(currentQuestion);
  131.  
  132.         yield return new WaitForSeconds(timeBetweenQuestions);
  133.  
  134.         Destroy(_instance);
  135.         Destroy(_instance2);
  136.         Destroy(_instance3);
  137.         Destroy(_instance4);
  138.         Destroy(_instance5);
  139.         Destroy(_instance6);
  140.         Destroy(_instance7);
  141.         Destroy(_instance8);
  142.  
  143.         isAnswered = false;
  144.  
  145.         SetCurrentQuestion();
  146.     }
  147.  
  148.     public void UserSelectOne()
  149.     {
  150.         if (currentQuestion.isOne && !isAnswered)
  151.         {
  152.             AddScore(1);
  153.             cubo1.GetComponent<Renderer>().material = good;
  154.             _instance = (GameObject) Instantiate(goed, pos1.transform.position, goed.transform.rotation);
  155.             isAnswered = true;
  156.             StartCoroutine(TransitionToNextQuestion());
  157.         }
  158.         else
  159.         {
  160.             if (!isAnswered)
  161.             {
  162.                 AddScore(-1);
  163.                 cubo1.GetComponent<Renderer>().material = notGood;
  164.                 _instance2 = (GameObject)Instantiate(fout, pos1.transform.position, fout.transform.rotation);
  165.                 isAnswered = true;
  166.                 StartCoroutine(TransitionToNextQuestion());
  167.             }
  168.         }
  169.  
  170.         //StartCoroutine(TransitionToNextQuestion());
  171.     }
  172.  
  173.     public void UserSelectTwo()
  174.     {
  175.         if (currentQuestion.isTwo && !isAnswered)
  176.         {
  177.             AddScore(1);
  178.             cubo2.GetComponent<Renderer>().material = good;
  179.             _instance3 = (GameObject) Instantiate(goed, pos2.transform.position, goed.transform.rotation);
  180.             isAnswered = true;
  181.             StartCoroutine(TransitionToNextQuestion());
  182.         }
  183.         else
  184.         {
  185.             if (!isAnswered)
  186.             {
  187.                 AddScore(-1);
  188.                 cubo2.GetComponent<Renderer>().material = notGood;
  189.                 _instance4 = (GameObject)Instantiate(fout, pos2.transform.position, fout.transform.rotation);
  190.                 isAnswered = true;
  191.                 StartCoroutine(TransitionToNextQuestion());
  192.             }
  193.  
  194.         }
  195.  
  196.         //StartCoroutine(TransitionToNextQuestion());
  197.     }
  198.  
  199.     public void UserSelectThree()
  200.     {
  201.         if (currentQuestion.isThree && !isAnswered)
  202.         {
  203.             AddScore(1);
  204.             cubo3.GetComponent<Renderer>().material = good;
  205.             _instance5 = (GameObject)Instantiate(goed, pos3.transform.position, goed.transform.rotation);
  206.             isAnswered = true;
  207.             StartCoroutine(TransitionToNextQuestion());
  208.         }
  209.         else
  210.         {
  211.             if (!isAnswered)
  212.             {
  213.                 AddScore(-1);
  214.                 cubo3.GetComponent<Renderer>().material = notGood;
  215.                 _instance6 = (GameObject)Instantiate(fout, pos3.transform.position, fout.transform.rotation);
  216.                 isAnswered = true;
  217.                 StartCoroutine(TransitionToNextQuestion());
  218.             }
  219.         }
  220.  
  221.         //StartCoroutine(TransitionToNextQuestion());
  222.     }
  223.  
  224.     public void UserSelectFour()
  225.     {
  226.         if (currentQuestion.isFour && !isAnswered)
  227.         {
  228.             AddScore(1);
  229.             cubo4.GetComponent<Renderer>().material = good;
  230.             _instance7 = (GameObject) Instantiate(goed, pos4.transform.position, goed.transform.rotation);
  231.             isAnswered = true;
  232.             StartCoroutine(TransitionToNextQuestion());
  233.         }
  234.         else
  235.         {
  236.             if (!isAnswered)
  237.             {
  238.                 AddScore(-1);
  239.                 cubo4.GetComponent<Renderer>().material = notGood;
  240.                 _instance8 = (GameObject)Instantiate(fout, pos4.transform.position, fout.transform.rotation);
  241.                 isAnswered = true;
  242.                 StartCoroutine(TransitionToNextQuestion());
  243.             }
  244.         }
  245.  
  246.         //StartCoroutine(TransitionToNextQuestion());
  247.     }
  248.  
  249.     public void UserSelectBack()
  250.     {
  251.         SceneManager.LoadScene(0);
  252.     }
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement