Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine.UI;
- public class FountainAnswer : GameManager
- {
- // stores unanswered questions in an array list to the Storage script of it's corresponding location.
- public FountainStorage[] questions; // an array or list of questions
- private static List<FountainStorage> unansweredQuestions; // a list of unanswered questions
- private FountainStorage currentQuestion; // the question to be prompted to the user
- [SerializeField]
- //shows the background and buttons of the menu. objets are applied through the game manager
- protected Text factText;
- public GameObject randPanel;
- public GameObject fountainYes;
- public GameObject fountainNo;
- void Start()
- {
- // makes sure there are no questions in the list and then adds them from the inspector when the game begins.
- if (unansweredQuestions == null || unansweredQuestions.Count == 0)
- {
- unansweredQuestions = questions.ToList<FountainStorage>(); //add the list of questions from the array to the unasweredQuestions list
- }
- //declares button listner and the function to be performed if clicked
- Button y = gameObject.GetComponent<Button>();
- y.onClick.AddListener(Yes);
- Button n = gameObject.GetComponent<Button>();
- n.onClick.AddListener(No);
- randPanel.SetActive(false);
- }
- // presents the current question from the numbered list of questions and and sets the text to the current question.
- public void SetCurrentQuestion()
- {
- int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
- currentQuestion = unansweredQuestions[randomQuestionIndex];
- factText.text = currentQuestion.fact;
- Debug.Log(factText.text);
- }
- //gives the current question is the activator is true and if the menu is already active.
- void Update()
- {
- if (randPanel.activeInHierarchy == true && activateFountainQuestion == true)
- {
- timeFactor = 0;
- activateFountainQuestion = false;
- SetCurrentQuestion();
- }
- }
- //checks for the type of question and applies the method depending if the user selects Yes or No
- public void Yes()
- {
- switch (currentQuestion.type)
- {
- //effects esteem depending on the type of question
- case 'A':
- PosA();
- break;
- case 'B':
- PosB();
- break;
- }
- }
- //checks for the type of question and applies the method depending if the user selects Yes or No
- public void No()
- {
- //effects esteem depending on the type of question
- switch (currentQuestion.type)
- {
- case 'A':
- NegA();
- break;
- case 'B':
- NegB();
- break;
- }
- }
- //===================================================================================================================================================
- //effects esteem depending on the type of question
- public void PosA()
- {
- esteem += 5;
- }
- public void PosB()
- {
- esteem += 20;
- }
- public void NegA()
- {
- esteem -= 5;
- Debug.Log("esteem: " + esteem);
- }
- public void NegB()
- {
- esteem -= 20;
- Debug.Log("esteem: " + esteem);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement