Advertisement
zhardyCode

Education Game - Fountain Answer

Mar 29th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.56 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine.UI;
  6.  
  7. public class FountainAnswer : GameManager
  8. {
  9.  
  10.     // stores unanswered questions in an array list to the Storage script of it's corresponding location.
  11.     public FountainStorage[] questions; // an array or list of questions
  12.     private static List<FountainStorage> unansweredQuestions; // a list of unanswered questions
  13.     private FountainStorage currentQuestion; // the question to be prompted to the user
  14.     [SerializeField]
  15.  
  16.     //shows the background and buttons of the menu. objets are applied through the game manager
  17.     protected Text factText;
  18.     public GameObject randPanel;
  19.     public GameObject fountainYes;
  20.     public GameObject fountainNo;
  21.  
  22.     void Start()
  23.     {
  24.         // makes sure there are no questions in the list and then adds them from the inspector when the game begins.
  25.         if (unansweredQuestions == null || unansweredQuestions.Count == 0)
  26.         {
  27.             unansweredQuestions = questions.ToList<FountainStorage>(); //add the list of questions from the array to the unasweredQuestions list
  28.         }
  29.  
  30.  
  31.         //declares button listner and the function to be performed if clicked
  32.         Button y = gameObject.GetComponent<Button>();
  33.         y.onClick.AddListener(Yes);
  34.  
  35.         Button n = gameObject.GetComponent<Button>();
  36.         n.onClick.AddListener(No);
  37.         randPanel.SetActive(false);
  38.     }
  39.  
  40.     // presents the current question from the numbered list of questions and and sets the text to the current question.
  41.     public void SetCurrentQuestion()
  42.     {
  43.         int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
  44.         currentQuestion = unansweredQuestions[randomQuestionIndex];
  45.  
  46.         factText.text = currentQuestion.fact;
  47.         Debug.Log(factText.text);
  48.  
  49.  
  50.     }
  51.  
  52.     //gives the current question is the activator is true and if the menu is already active.
  53.     void Update()
  54.     {
  55.         if (randPanel.activeInHierarchy == true && activateFountainQuestion == true)
  56.         {
  57.             timeFactor = 0;
  58.             activateFountainQuestion = false;
  59.             SetCurrentQuestion();
  60.         }
  61.     }
  62.  
  63.     //checks for the type of question and applies the method depending if the user selects Yes or No
  64.     public void Yes()
  65.     {
  66.         switch (currentQuestion.type)
  67.         {
  68.             //effects esteem depending on the type of question
  69.             case 'A':
  70.                 PosA();
  71.                 break;
  72.  
  73.             case 'B':
  74.                 PosB();
  75.                 break;
  76.         }
  77.     }
  78.     //checks for the type of question and applies the method depending if the user selects Yes or No
  79.  
  80.     public void No()
  81.     {
  82.         //effects esteem depending on the type of question
  83.         switch (currentQuestion.type)
  84.         {
  85.             case 'A':
  86.                 NegA();
  87.                 break;
  88.  
  89.             case 'B':
  90.                 NegB();
  91.                 break;
  92.         }
  93.     }
  94.  
  95.     //===================================================================================================================================================
  96.  
  97.  
  98.     //effects esteem depending on the type of question
  99.     public void PosA()
  100.     {
  101.         esteem += 5;
  102.        
  103.  
  104.     }
  105.  
  106.     public void PosB()
  107.     {
  108.         esteem += 20;
  109.     }
  110.  
  111.  
  112.     public void NegA()
  113.     {
  114.         esteem -= 5;
  115.         Debug.Log("esteem: " + esteem);
  116.     }
  117.  
  118.     public void NegB()
  119.     {
  120.         esteem -= 20;
  121.         Debug.Log("esteem: " + esteem);
  122.     }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement