Quiz Game Video 3

Updated on April 6, 2017 in [A] Brackeys Courses
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on April 4, 2017

Hi All! I am brand new to Unity, and to coding in general! I was hoping someone could post his or her Game Manager code at the end of the video tutorial so I could compare it to my own. My game will not animate and I have spent hours trying to figure out why. Thank you in advance for your help!

  • Liked by
Reply
1 on April 4, 2017

In every Brackeys’ video in description there is a link to the finished code.

on April 4, 2017

I am sorry, but where? I see other people posting their code asking for help. I just need a copy of the accurate code as written in the video.

Show more replies
  • Liked by
Reply
Cancel
0 on April 6, 2017

Don’t know why he didn’t put the code in the description. I did some digging and I found my quiz project I did after his tutorial, here is the code of the GameManager:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
// TODO: Write code that will check if it asks 2 same questions in a row
public class GameManager : MonoBehaviour
{
    public Question[] questions;
    private static List<Question> unansweredQuestions;
    private Question currentQuestion;
    [SerializeField]
    private Text factText;
    [SerializeField]
    private Text trueAnswerText;
    [SerializeField]
    private Text falseAnswerText;
    [SerializeField]
    private Transform trueButton;
    [SerializeField]
    private Transform falseButton;
    [SerializeField]
    private Animator animator;
    [SerializeField]
    private float timeBetweenQuestions = 1f;
    void Start()
    {
        if (unansweredQuestions == null || unansweredQuestions.Count == 0)
        {
            unansweredQuestions = questions.ToList<Question>();
        }
        SetCurrentQuestion();
    }
    void SetCurrentQuestion()
    {
        int randomQuestionIndex = Random.Range(0, unansweredQuestions.Count);
        currentQuestion = unansweredQuestions[randomQuestionIndex];
        factText.text = currentQuestion.fact;
        if(currentQuestion.isTrue)
        {
            trueAnswerText.text = "CORRECT";
            falseAnswerText.text = "WRONG";
        }
        else
        {
            trueAnswerText.text = "WRONG";
            falseAnswerText.text = "CORRECT";
        }
    }
    IEnumerator transitionToNextQuestion()
    {
        unansweredQuestions.Remove(currentQuestion);
        yield return new WaitForSeconds(timeBetweenQuestions);
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
    public void UserSelectTrue()
    {
        animator.SetTrigger("True");
        StartCoroutine(transitionToNextQuestion());
    }
    public void UserSelectFalse()
    {
        animator.SetTrigger("False");
        StartCoroutine(transitionToNextQuestion());
    }
}
  • Liked by
Reply
Cancel