Beispiel #1
0
 // Start is called before the first frame update
 void Start()
 {
     questions = previousLevelData.GetQuestions();
     answers   = previousLevelData.GetAnswers();
     attempts  = previousLevelData.GetAttempts();
     ActivateMainSumary();
 }
Beispiel #2
0
    void Awake()
    {
        stateMachine = Camera.main.GetComponent <StateMachine>().levelData;

        updateUI = GameObject.FindGameObjectWithTag("MainCanvas").GetComponent <UpdateUI>();

        incorrectlyAnsweredQs.Add(-1);

        questions  = stateMachine.GetQuestions();
        allAnswers = stateMachine.allLevelAnswers;

        audioSource = GetComponent <AudioSource>();

        #region Error Prevention
        if ((allAnswers.Length) % 3 != 0)
        {
            Debug.LogError("Some questions do not have 3 answers");
            Application.Quit();
            return;
        }

        if ((questions.Length) * 3 != allAnswers.Length)
        {
            Debug.LogError("Number of questions is not relative to the amount of answers. 3 per Question");
            Application.Quit();
            return;
        }

        foreach (string answer in allAnswers)
        {
            try
            {
                string[] tempDiv = answer.Split(':');
                if (tempDiv[1] == "n")
                {
                }
                else if (tempDiv[1] == "y")
                {
                }
                else
                {
                    Debug.LogWarning(tempDiv[0] + " is incorrectly formatted");
                }
            }
            catch
            {
                Debug.LogError("Question " + answer + "is not formatted properly! " +
                               "Remember to include a ':' along with a 'y' or 'n' depending on if the answer is correct"); return;
            }
        }

        if (maxHP > 8)
        {
            maxHP = 8;
            Debug.LogWarning("HP cannot be higher than 8!");
        }
        #endregion

        curHP          = maxHP;
        answerArrays   = new string[questions.Length][];
        correctAnswers = new string[questions.Length];

        int allAnswerCounter = 0;
        for (int i = 0; i < questions.Length; i++)
        {
            answerArrays[i] = new string[3] {
                allAnswers[allAnswerCounter], allAnswers[allAnswerCounter + 1], allAnswers[allAnswerCounter + 2]
            };

            ParseCorrectAnswer(i);

            allAnswerCounter += 3;
        }

        #region Debug Output
        //int r = 0;
        //for (int d=0; d < answerArrays.Length; d++)
        //{
        //    Debug.Log("Question " + d);
        //    Debug.Log(answerArrays[d][r]);
        //    Debug.Log(answerArrays[d][r+1]);
        //    Debug.Log(answerArrays[d][r+2]);
        //    Debug.Log("--------------------");
        //}

        //for (int c=0; c < correctAnswers.Length; c++)
        //{
        //    Debug.Log(correctAnswers[c]);
        //}
        #endregion
    }