using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class QuizManager : MonoBehaviour
{
public List QnA;
public GameObject[] options;
public int currentQuestion;
public GameObject Quizpanel;
public GameObject GoPanel;
public GameObject Stars;
public Text QuestionTxt;
public Text ScoreTxt;
public float scorePer;
int totalQuestions = 0;
public int score;
private void Start()
{
totalQuestions = QnA.Count;
GoPanel.SetActive(false);
generateQuestion();
}
public void retry()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void GameOver()
{
Quizpanel.SetActive(false);
GoPanel.SetActive(true);
ScoreTxt.text = score + "/" + totalQuestions;
scorePer = (correct / totalQuestions) * 100;
ScoreTxt.GetComponent<Text>().text = "Score : " + scorePer" %";
GetComponent<starsHolder>().starsAchieved();
}
public void starsAcheived()
{
int scoreWrong = QnA.Count;
int scoreCorrect = totalQuestions - scoreWrong;
float percentage = scoreCorrect / totalQuestions;
if (percentage >= 33f && percentage < 66)
{
//one star
Stars[0].SetActive(true);
}
else if (percentage >= 66 && percentage < 70)
{
//two stars
Stars[0].SetActive(true);
Stars[1].SetActive(true);
}
else
{
Stars[0].SetActive(true);
Stars[1].SetActive(true);
Stars[3].SetActive(true);
}
}
public void correct()
{
//when you are right
score += 1;
QnA.RemoveAt(currentQuestion);
generateQuestion();
}
public void wrong()
{
//when you answer wrong
QnA.RemoveAt(currentQuestion);
generateQuestion();
}
void SetAnswers()
{
for (int i = 0; i < options.Length; i++)
{
options*.GetComponent<AnswerScript>().isCorrect = false;*
options_.transform.GetChild(0).GetComponent().text = QnA[currentQuestion].Answers*;*_
* if(QnA[currentQuestion].CorrectAnswer == i+1)*
* {*
_ options*.GetComponent().isCorrect = true;
}
}
}*_
void generateQuestion()
{
* if(QnA.Count > 0)*
* {*
* currentQuestion = Random.Range(0, QnA.Count);*
* QuestionTxt.text = QnA[currentQuestion].Question;*
* SetAnswers();*
* }*
* else*
* {*
* Debug.Log(“Out of Questions”);*
* GameOver();*
* }*
}
}