Help Me With A Quiz Game

Updated on June 27, 2017 in [A] Tutorials
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
7 on June 25, 2017

Hey there thanks for reading my post. I am a New Unity User. I made a 2D Quiz game following Brackeys Quiz game tutorial. Now I want to add Score and Life system in it. How to do that? Here is the code :

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

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 Animator animator;

[SerializeField]
private float timeBetweenQuestions = 1f;

public Text scoreText;
public int score = 0;
public int life = 5;

public Sprite [] gamelife;

public Image hearts;

void Start()
{

if (unansweredQuestions == null || unansweredQuestions.Count == 0) {
unansweredQuestions = questions.ToList<Question> ();

}

SetCurrentQuestion ();

}

void scoreCount()
{
if (currentQuestion.isTrue) {
score += 1;
scoreText.text = score.ToString ();
}
}

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 UserSelecTrue()
{
animator.SetTrigger (“True”);

if (currentQuestion.isTrue) {
Debug.Log (“CORRECT!”);

} else
{
Debug.Log(“WRONG”);

}

StartCoroutine (TransitionToNextQuestion ());

}

public void UserSelecFalse()
{
animator.SetTrigger (“False”);

if (!currentQuestion.isTrue) {
Debug.Log (“CORRECT!”);

} else
{
Debug.Log(“WRONG”);
}

StartCoroutine (TransitionToNextQuestion ());
}

public void BackToMenu()
{
SceneManager.LoadScene (“Main Menu”);
}

public void QUIT()
{
Application.Quit ();
}
}

Please help me….A little help will be appreciated largely. 

  • Liked by
Reply
0 on June 25, 2017

We are not your personal programmers. If you don’t know how to do that go back to basics

  • Liked by
Reply
Cancel
0 on June 25, 2017

Oh…thanks for your suggestion I thought I could get help here

  • Liked by
Reply
Cancel
4 on June 25, 2017

Well that’s the problem with following tutorials that closely. You don’t know what you’re writing exactly, or at least how to make it.

I recommend starting something from scratch yourself, without following a tutorial. That’s the best way to learn.

 

on June 26, 2017

Thanks bro any suggestions where to start? And can you provide me some tutorials?

Devoted
on June 26, 2017

He just said you shouldn’t use tutorials…

Guru
on June 26, 2017

Indeed, at least not as the base of your game.
Smaller things are fine, like:
How to make a healthbar
How to detect if I hit something
How to pickup an object and throw it away
Etc…

 

on June 27, 2017

Oh……Thanks

Show more replies
  • Liked by
Reply
Cancel