- Home /
Question by
hyunnismly · Mar 05, 2019 at 01:56 AM ·
unity 3.5
Score board do not respond..,Quiz score board does not respond
Hello. I am trying to do quiz game though youtube Patrik youtubers Quiz Game But somehow the score board does not respond . Any idea what wrong in the code ?
respond.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class respond : MonoBehaviour
{
private int idthemes;
public Text Question;
public Text answerA;
public Text answerB;
public Text answerC;
public Text answerD;
public Text infoAnswer;
public string[] questions; //store question
public string[] alternateA; //store alternateA
public string[] alternateB; //store alternateB
public string[] alternateC; //store alternateC
public string[] alternateD; //store alternateD
public string[] correct; //store alternatecorrect
private int idQuestion;
private float hitQ;
private float questionsss;
private float media;
private int notaFinal;
// Start is called before the first frame update
void Start()
{
idthemes = PlayerPrefs.GetInt("idthemes");
idQuestion = 0;
questionsss = questions.Length;
Question.text = questions[idQuestion];
answerA.text = alternateA[idQuestion];
answerB.text = alternateB[idQuestion];
answerC.text = alternateC[idQuestion];
answerD.text = alternateD[idQuestion];
infoAnswer.text = "Answer " + (idQuestion + 1).ToString() + " of " + questionsss.ToString() + " Questions.";
}
public void answer (string alternate)
{
if (alternate == "A")
{
//execute answer A
if(alternateA[idQuestion] == correct[idQuestion])
{
hitQ += 1;
}
}
else if (alternate == "B")
{
//execute answer B
if (alternateA[idQuestion] == correct[idQuestion])
{
hitQ += 1;
}
}
else if (alternate == "C")
{
//execute answer C
if (alternateA[idQuestion] == correct[idQuestion])
{
hitQ += 1;
}
}
else if (alternate == "D")
{
//execute answer D
if (alternateA[idQuestion] == correct[idQuestion])
{
hitQ += 1;
}
}
nextQuestion();
}
void nextQuestion()
{
idQuestion += 1;
if (idQuestion <= (questionsss - 1))
{
Question.text = questions[idQuestion];
answerA.text = alternateA[idQuestion];
answerB.text = alternateB[idQuestion];
answerC.text = alternateC[idQuestion];
answerD.text = alternateD[idQuestion];
infoAnswer.text = "Answer " + (idQuestion + 1).ToString() + "of " + questionsss.ToString() + " Questions.";
}
else
{
//what to do if question finish
media = 10 * (hitQ / questionsss); //calculate into percent
notaFinal = Mathf.RoundToInt(media); //round off
if(notaFinal > PlayerPrefs.GetInt("notaFinal"+idthemes.ToString()))
{
PlayerPrefs.SetInt("notaFinal"+idthemes.ToString(),notaFinal);
PlayerPrefs.SetInt("hitQ"+idthemes.ToString(),(int) hitQ);
}
PlayerPrefs.SetInt("notaFinalTemp" + idthemes.ToString(), notaFinal);
PlayerPrefs.SetInt("hitQTemp" + idthemes.ToString(), (int)hitQ);
Application.LoadLevel("notaFinal");
}
}
}
notaFinal.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class notaFinal : MonoBehaviour
{
private int idthemes;
public Text txtnota;
public Text txtinfothemes;
public GameObject star1;
public GameObject star2;
public GameObject star3;
private int notaF;
private int acertos;
// Start is called before the first frame update
void Start()
{
idthemes = PlayerPrefs.GetInt("idthemes");
notaF = PlayerPrefs.GetInt("notaFinalTemp" + idthemes.ToString());
acertos = PlayerPrefs.GetInt("hitQTemp" + idthemes.ToString());
txtnota.text = notaF.ToString();
txtinfothemes.text= "Correct "+acertos.ToString();
}
// Update is called once per frame
void Update()
{
}
}
Comment
txtnota.text = notaF.ToString(); // display score
txtinfothemes.text= "Correct "+acertos.ToString(); //display correct question
what the error, and what do you mean by not respond? it doesn't return a value(wether correct/not)?
@king_opping sorry... it respond .. but always " 0 " even though i answer the questions correctly.
screenshot-4.png
(489.5 kB)