Prefabs for first 2 questions

This commit is contained in:
Mediha Zukic
2017-05-18 22:10:17 +03:00
parent 2a365fa365
commit 115885da90
56 changed files with 25609 additions and 905 deletions

View File

@@ -1,16 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ObjectController : MonoBehaviour {
public RawImage imageCorrect;
public RawImage imageIncorrect;
// Use this for initialization
void Start () {
imageCorrect.enabled = false;
imageIncorrect.enabled = false;
}
// Update is called once per frame
void Update () {
}
}

View File

@@ -29,7 +29,11 @@ public class QuizController : MonoBehaviour {
private const int counterInitialValue = 10;
private const int displayAnswersCounterValue = 3;
private const int counterDisplayAnswersInitialValue = 3;
private float counterDisplayAnswersValue;
private bool counterDisplayAnswersStarted = false;
private int scoreValue = 0;
@@ -38,10 +42,25 @@ public class QuizController : MonoBehaviour {
private List<int> selectedAnswers;
List<Question> questions = new List<Question>() {
new Question("1. Neki od ovih prozora imaju 2-3 puta manje toplotnih gubitaka za razliku od drugih, koji su to?", new int[] {1, 3}),
new Question("2. Na jedan od načina možete uštedjeti i do 10 litara vode po osobi dnevno, uz koji predmet?", new int[] {2}),
new Question("1. Neki od ovih prozora imaju 2-3 puta manje toplotnih gubitaka za razliku od drugih, koji su to?", new int[] {1, 4}),
new Question("2. Na jedan od načina možete uštedjeti i do 10 litara vode po osobi dnevno, uz koji predmet?", new int[] {3, 4}),
};
List<Question> q = new List<Question>()
{
new Question("3. Korištenjem jednog od sljedećih predmeta, u svjetlost se pretvara svega 5% uložene energije, dok se ostatak pretvara u toplotu, koji je to?", new int[] {1}),
new Question("4. Neki od navedenih predmeta uključeni u utičnicu, iako nisu u u funkciji, i dalje se znatno griju i troše električnu energiju.", new int[] {3}),
new Question("5. Šta možemo ugraditi na radijatore da nam pomogne smanjiti troškove grijanja za 7-15%?", new int[] {1, 3}),
new Question("6. Ako je vani temperatura 33oC, koja je optimalna temperatura u kući? ", new int[] {4}),
new Question("7. Kakvim načinom pranja posuđa, i uz koji uređaj od navedenih, trošimo 60% manje električne energije i do 85% manje vode?", new int[] {2, 3}),
new Question("8. Koji uređaj u «stand by» načinu rada troši i do 24% energije u odnosu na potrošnju energije kada je upaljen?", new int[] {4}),
new Question("9. Jednom godišnje stručna osoba treba provjeriti prohodnost čega? Loša prohodnost doprinosi većoj potrošnji energije za grijanje.", new int[] {1}),
new Question("10. Uvijek odaberite program s najnižom temperaturom vode koji još uvijek obezbjeđuje dobar kvalitet pranja, za šta od navedenog? ", new int[] {1, 4}),
};
public GameObject objController;
// Use this for initialization
void Start () {
selectedAnswers = new List<int>();
@@ -50,8 +69,28 @@ public class QuizController : MonoBehaviour {
UpdateCounter();
UpdateScore();
btnNextQuestion.GetComponent<Button>().onClick.AddListener(LoadNextQuestion);
/*
// Instantiate the wreck game object at the same position we are at
GameObject wreckClone = (GameObject)Instantiate(objController, new Vector3(0, 2, -7), Quaternion.identity);
// Sometimes we need to carry over some variables from this object
// to the wreck
wreckClone.GetComponent<ObjectController>().imageCorrect.enabled = true;
wreckClone.GetComponent<ObjectController>().imageIncorrect.enabled = false;
// Instantiate the wreck game object at the same position we are at
GameObject wreckClone1 = (GameObject)Instantiate(objController, new Vector3(-5, 2, -7), Quaternion.identity);
// Sometimes we need to carry over some variables from this object
// to the wreck
wreckClone1.GetComponent<ObjectController>().imageCorrect.enabled = false;
wreckClone1.GetComponent<ObjectController>().imageIncorrect.enabled = true;
//Instantiate(Resources.Load("Prefabs/AnswerGameObject") as GameObject, new Vector3(0, 2, -7), Quaternion.identity);*/
}
// Update is called once per frame
void Update()
{
@@ -60,12 +99,22 @@ public class QuizController : MonoBehaviour {
counterValue -= Time.deltaTime;
UpdateCounter();
}
else
{
LoadNextQuestion();
counterValue = counterInitialValue;
}
if (counterDisplayAnswersValue > 0 && counterDisplayAnswersStarted)
counterDisplayAnswersValue -= Time.deltaTime;
else
{
UpdateScene();
counterDisplayAnswersStarted = false;
}
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
@@ -77,6 +126,8 @@ public class QuizController : MonoBehaviour {
int answerIdx = GetAnswerIdx(hit.transform.gameObject.name) - numberOfAnswers * questionIdx;
if (!selectedAnswers.Contains(answerIdx))
selectedAnswers.Add(answerIdx);
else
selectedAnswers.Remove(answerIdx);
}
}
}
@@ -85,10 +136,11 @@ public class QuizController : MonoBehaviour {
{
scoreValue += GetScore();
UpdateScore();
questionIdx = (questionIdx + 1) % 2;
selectedAnswers.Clear();
UpdateScene();
counterValue = counterInitialValue;
counterDisplayAnswersValue = counterDisplayAnswersInitialValue;
counterDisplayAnswersStarted = true;
ShowAnswers();
questionIdx = (questionIdx + 1) % 2;
}
private void UpdateScore()
@@ -101,8 +153,24 @@ public class QuizController : MonoBehaviour {
counterText.text = counterValue.ToString("f0");
}
private void ShowAnswers()
{
for(int i = numberOfAnswers * questionIdx; i < numberOfAnswers * (questionIdx + 1); i++)
{
MarkAnswer(questions[questionIdx].getCorrectAnswers().Contains(i - questionIdx * numberOfAnswers + 1), i);
}
}
private void MarkAnswer(bool isCorrect, int idx)
{
answers[idx].GetComponent<ObjectController>().imageCorrect.enabled = isCorrect;
answers[idx].GetComponent<ObjectController>().imageIncorrect.enabled = !isCorrect;
}
// Update scene with new question + answers
private void UpdateScene()
{
RemoveMarks();
// Set new question
questionText.text = questions[questionIdx].getQuestionText();
// Set right answers
@@ -110,7 +178,6 @@ public class QuizController : MonoBehaviour {
{
if (i >= numberOfAnswers * questionIdx && i < numberOfAnswers * (questionIdx + 1))
{
Debug.Log("Set active: " + i);
answers[i].SetActive(true);
}
else
@@ -118,6 +185,15 @@ public class QuizController : MonoBehaviour {
}
}
private void RemoveMarks()
{
foreach(GameObject answer in answers)
{
answer.GetComponent<ObjectController>().imageCorrect.enabled = false;
answer.GetComponent<ObjectController>().imageIncorrect.enabled = false;
}
}
private int GetAnswerIdx(string gameObjName)
{
string resultString = Regex.Match(gameObjName, @"\d+").Value;