thanks for your reply.
herwe is my complete code.
I am not a pro in coding, my code is too lengthy i feel. but here it is:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
//using UnityEngine.UI.Button;
using UnityEngine.SceneManagement;
public class QuizManager : MonoBehaviour {
public float gazeTime = 2f;
public float myTime;
private bool gazedAt;
//canvas where the question appears
public GameObject questionCanvas;
//Score Canvas
public GameObject scorecanvas;
//answer
public GameObject btnanswer;
public GameObject btnchoice2;
public GameObject btnchoice3;
public GameObject btnq2choice2;
public GameObject btnq2choice3;
public GameObject btnq2answer;
public GameObject btnq3choice2;
public GameObject btnq3choice3;
public GameObject btnq3answer;
public GameObject btnscore;
public GameObject btnexit;
//question title
public Text questionTitle;
//score text
public Text scoreText;
//video player
public VideoPlayer player;
//response
public bool ans;
//audio
public AudioSource audsrc;
//flag to indicate whether we are showing questions or not
bool isShowingQuestions;
//Quiz
Quiz quiz;
//time(used to show questions)
float elapsedTime = 0;
//next question
Question nextQuestion;
//ocunter for changing button text
private int i = 0;
//next question Index
int nextQuestionIndex;
//total correct answers
static public int totalCorrect = 0;
//total questions
static public int numQuestionsResponded;
public Text Vidtitle;
//this variable will be used for testing purpose for getString for video title
//public Text v2;
string v;
public int counter = 0;
public bool resp;
//to exit video
public string endvideo;
public string exitvideo;
void Start () {
//v = Vidtitle.text.ToString();
Vidtitle= GameObject.Find("VideoTitle").GetComponent<Text>();
//this line is to check if the video title is being retrieved
//Debug.Log(Vidtitle.text);
PlayerPrefs.SetString("VideoTit", Vidtitle.text);
//this line is to check if the video title is stored correctly in playerprefs
Debug.Log(Vidtitle.text);
//these next two lines are to check if playerprefs gets the correct video title
//v2.text= PlayerPrefs.GetString("VideoTit");
//Debug.Log(v2.text);
//pause quiz
PauseQuiz();
//hide question canvas
questionCanvas.SetActive(false);
//hide score canvas
scorecanvas.SetActive(false);
btnscore.SetActive(false);
btnexit.SetActive(true);
//prepare quiz first(questions of the quiz)
quiz = new Quiz();
quiz.questions = new Question[5];
quiz.questions[0] = new Question();
quiz.questions[0].time = 27;
quiz.questions[0].title = "Lions like to __ running";
quiz.questions[0].correct = true;
quiz.questions[1] = new Question();
quiz.questions[1].time = 41;
quiz.questions[1].title = "The African Lion Population_____ dropped by over 50%";
quiz.questions[1].correct = true;
quiz.questions[2] = new Question();
quiz.questions[2].time = 148;
quiz.questions[2].title = "Lionesses like lions with ____, _____ manes";
quiz.questions[2].correct = true;
quiz.questions[3] = new Question();
quiz.questions[3].time = 150;
quiz.questions[3].title = "The lion moves _____ the camera";
quiz.questions[3].correct = true;
quiz.questions[4] = new Question();
quiz.questions[4].time = 156;
quiz.questions[4].title = "The lion ______ the camera";
quiz.questions[4].correct = true;
//prepare nrxt question
PrepareNext();
}
// Update is called once per frame
void Update () {
if (gazedAt&&counter==0)
{
myTime += Time.deltaTime;
if (myTime >= 3)
{
HandleAnswer(resp);
}
}
if(endvideo=="yes")
{
myTime += Time.deltaTime;
if(myTime>=3)
{
ExitVid();
}
}
if (exitvideo == "yes")
{
myTime += Time.deltaTime;
if (myTime >= 3)
{
QuitVid();
}
}
//check that we should be showing questions
if (!isShowingQuestions) return;
//increase the elapsed time by the amount that has happened since the last loop
elapsedTime += Time.deltaTime;
//check time, if a quesiton is due, show it
if(elapsedTime>nextQuestion.time)
{
//show question
//1)show question canvas
questionCanvas.SetActive(true);
scorecanvas.SetActive(true);
//2) show the question title
questionTitle.text = nextQuestion.title;
// btnanswer.GetComponentInChildren<Text>().text = "has";
//3) Pause the quiz
PauseQuiz();
}
}
void PauseQuiz()
{
//video paused
AudioListener.pause = true;
player.Pause();
//no showing question
isShowingQuestions = false;
}
void ResumeQuiz()
{
AudioListener.pause = false;
//continue playing video
player.Play();
changebtntext();
//continue playing audio
//continue measuring time elapsed
isShowingQuestions = true;
}
void PrepareNext()
{
//setting the first value
if(nextQuestion==null)
{
//set index to the start of the array
nextQuestionIndex = 0;
//get next question
nextQuestion = quiz.questions[nextQuestionIndex];
}
else
{
//increase the next question index
nextQuestionIndex++;
//check that there are more questions left
if(nextQuestionIndex < quiz.questions.Length)
{
//get next question
nextQuestion = quiz.questions[nextQuestionIndex];
}
else
{
//Quiz is over
print("Video completed!");
scoreText.text += "
Quiz Completed!";
questionCanvas.SetActive(false);
player.Play();
AudioListener.pause = false;
return;
}
}
ResumeQuiz();
}
void changebtntext()
{
if(i==0)
{
if (btnanswer.GetComponentInChildren<Text>().text == "null")
{
btnanswer.GetComponentInChildren<Text>().text = "go";
btnchoice2.GetComponentInChildren<Text>().text = "be";
btnchoice3.GetComponentInChildren<Text>().text = "do";
btnq2answer.SetActive(false);
btnq2choice2.SetActive(false);
btnq2choice3.SetActive(false);
btnq3answer.SetActive(false);
btnq3choice2.SetActive(false);
btnq3choice3.SetActive(false);
// btnexit.SetActive(false);
i = i + 1;
Debug.Log("i = " + i);
}
}
else if (i == 1)
{
btnq2choice2.GetComponentInChildren<Text>().text = "have";
btnq2choice3.GetComponentInChildren<Text>().text = "is";
btnq2answer.GetComponentInChildren<Text>().text = "has";
btnq2answer.SetActive(true);
btnq2choice2.SetActive(true);
btnq2choice3.SetActive(true);
btnanswer.SetActive(false);
btnchoice2.SetActive(false);
btnchoice3.SetActive(false);
i = i + 1;
Debug.Log("i = " + i);
}
else if (i == 2)
{
btnq3answer.GetComponentInChildren<Text>().text = "darker,thicker";
btnq3choice2.GetComponentInChildren<Text>().text = "more dark,more thick";
btnq3choice3.GetComponentInChildren<Text>().text = "darkest,thickest";
btnq3answer.SetActive(true);
btnq3choice2.SetActive(true);
btnq3choice3.SetActive(true);
btnanswer.SetActive(false);
btnchoice2.SetActive(false);
btnchoice3.SetActive(false);
btnq2answer.SetActive(false);
btnq2choice2.SetActive(false);
btnq2choice3.SetActive(false);
i = i + 1;
Debug.Log("i = " + i);
}
else if (i == 3)
{
btnanswer.GetComponentInChildren<Text>().text = "towards";
btnchoice2.GetComponentInChildren<Text>().text = "with";
btnchoice3.GetComponentInChildren<Text>().text = "away";
btnanswer.SetActive(true);
btnchoice2.SetActive(true);
btnchoice3.SetActive(true);
btnq2answer.SetActive(false);
btnq2choice2.SetActive(false);
btnq2choice3.SetActive(false);
btnq3answer.SetActive(false);
btnq3choice2.SetActive(false);
btnq3choice3.SetActive(false);
i = i + 1;
Debug.Log("i = " + i);
}
else if (i == 4)
{
btnq2choice2.GetComponentInChildren<Text>().text = "touch";
btnq2choice3.GetComponentInChildren<Text>().text = "will touch";
btnq2answer.GetComponentInChildren<Text>().text = "touched";
btnq2answer.SetActive(true);
btnq2choice2.SetActive(true);
btnq2choice3.SetActive(true);
btnanswer.SetActive(false);
btnchoice2.SetActive(false);
btnchoice3.SetActive(false);
btnq3answer.SetActive(false);
btnq3choice2.SetActive(false);
btnq3choice3.SetActive(false);
i = i + 1;
Debug.Log("i = " + i);
}
return;
}
public void PointerEnter(bool response1)
{
resp = response1;
gazedAt = true;
counter = 0;
}
public void HandleAnswer(bool response)
{
print("responded:" + response + "Correct answer" + nextQuestion.correct);
//check if the answer was correct
//hide the question canvas
questionCanvas.SetActive(false);
//increase the number of responded questions
numQuesResponded++;
Debug.Log(numQuesResponded);
if (response == nextQuestion.correct)
{
totalCorrect++;
scoreText.text = "Correct!";
}
else
{
scoreText.text = "Wrong";
}
scoreText.text += "
Score:" + totalCorrect + “/” + numQuesResponded;
if (numQuesResponded == 5)
{
scoreText.text = "Final Score:" + totalCorrect + "/" + numQuesResponded;
PlayerPrefs.SetString("FullScore", scoreText.text);
Debug.Log(scoreText.text);
// PlayerPrefs.SetString("VideoTitle", Vidtitle.text);
btnexit.SetActive(true);
scoreText.text += "
Quiz Over";
}
PrepareNext();
counter += 1;
myTime = 0f;
}
public void PointerExit()
{
gazedAt = false;
myTime = 0f;
exitvideo = "no";
}
public void PointerEndvideo()
{
gazedAt = true;
endvideo = "yes";
}
public void PointerExitvideo()
{
gazedAt = true;
exitvideo = "yes";
}
public void QuitVid()
{
PlayerPrefs.DeleteAll();
SceneManager.LoadScene("Home");
}
public void ExitVid()
{
SceneManager.LoadScene("ScoreReport");
}
}