Changes from email - glow, timers, floor texture

This commit is contained in:
Mediha Zukic
2017-05-23 19:39:06 +03:00
parent dd09c6f72f
commit 40cedaf5bf
58 changed files with 4679 additions and 1465 deletions

View File

@@ -13,37 +13,35 @@ public class Quiz2Controller : MonoBehaviour {
public GameObject[] answerModels;
public GameObject haloEffect;
public GameObject haloEffectRed;
public GameObject haloEffectGreen;
// References to answers
private List<GameObject> answers;
// References to answers halo prefabs
private List<GameObject> answersHaloEffects;
private List<GameObject> answersRedHaloEffects;
private List<GameObject> answersGreenHaloEffects;
private const int numberOfAnswers = 2;
private const int scoreCorrectAnswer = 10;
private const int scoreIncorrectAnswer = -15;
private const int scoreIncorrectAnswer = -10;
private const int scoreTimedOut = 0;
private const float counterInitialValue = 90;
private const int totalGameTime = 90;
private float totalTimePerQuestion;
private float counterValue;
private int scoreValue;
private int questionIdx;
private float counterValue;
private float counterPerQuestionValue;
private int selectedAnswerIdx;
private const int counterDisplayAnswersTotalValue = 3;
private const float counterDisplayAnswersTotalValue = 1.5f;
private float counterDisplayAnswersValue;
@@ -128,17 +126,17 @@ public class Quiz2Controller : MonoBehaviour {
// Init counters and score
questionIdx = 0;
scoreValue = 0;
counterValue = 0;
counterPerQuestionValue = 0;
counterValue = counterInitialValue;
counterDisplayAnswersValue = 0;
counterDisplayAnswersStarted = false;
totalTimePerQuestion = totalGameTime / questions.Count;
answers = new List<GameObject>();
answersHaloEffects = new List<GameObject>();
answersRedHaloEffects = new List<GameObject>();
answersGreenHaloEffects = new List<GameObject>();
UpdateCounter();
UpdateScore(true);
InstantiateAnswers();
InstantiateHaloPrefabs();
InstantiateRedHaloPrefabs();
InstantiateGreenHaloPrefabs();
UpdateScene();
}
@@ -148,13 +146,17 @@ public class Quiz2Controller : MonoBehaviour {
Debug.Log(counterDisplayAnswersValue.ToString());
// Main counter
// Game over
if (counterValue > totalGameTime)
if (counterValue < 0)
{
SceneManager.LoadScene("EntryScene");
counterValue += Time.deltaTime;
return;
}
counterValue -= Time.deltaTime;
UpdateCounter();
// Load next pair
if((counterDisplayAnswersValue > counterDisplayAnswersTotalValue) && counterDisplayAnswersStarted || (counterPerQuestionValue > totalTimePerQuestion && !counterDisplayAnswersStarted))
if((counterDisplayAnswersValue > counterDisplayAnswersTotalValue) && counterDisplayAnswersStarted)
{
// Load next pair
LoadNextPair();
@@ -163,9 +165,6 @@ public class Quiz2Controller : MonoBehaviour {
if (counterDisplayAnswersValue < counterDisplayAnswersTotalValue && counterDisplayAnswersStarted)
counterDisplayAnswersValue += Time.deltaTime;
if (counterPerQuestionValue < totalTimePerQuestion)
counterPerQuestionValue += Time.deltaTime;
// Select answers event handler
if (Input.GetMouseButtonDown(0))
@@ -181,7 +180,7 @@ public class Quiz2Controller : MonoBehaviour {
counterDisplayAnswersStarted = true;
// Set glow
selectedAnswerIdx = GetAnswerIdx(hit.transform.gameObject.name);
SetGlowEffect(selectedAnswerIdx, true);
SetGlowEffect(selectedAnswerIdx, true, IsAnswerCorrect(selectedAnswerIdx, questions[questionIdx].getCorrectAnswers()));
// Update score
UpdateScore();
}
@@ -196,7 +195,8 @@ public class Quiz2Controller : MonoBehaviour {
for (int i = 0; i < numberOfAnswers; i++)
{
int prefabIdx = questionIdx * numberOfAnswers + i;
answersHaloEffects[prefabIdx].SetActive(false);
answersRedHaloEffects[prefabIdx].SetActive(false);
answersGreenHaloEffects[prefabIdx].SetActive(false);
}
}
@@ -204,9 +204,12 @@ public class Quiz2Controller : MonoBehaviour {
/// Clears/Adds glow from a specific answer GameObject
/// </summary>
/// <param name="prefabIdx"></param>
private void SetGlowEffect(int prefabIdx, bool showGlowEffect)
{
answersHaloEffects[prefabIdx - 1].SetActive(showGlowEffect);
private void SetGlowEffect(int prefabIdx, bool showGlowEffect, bool isCorrectAnswer)
{
if(isCorrectAnswer)
answersGreenHaloEffects[prefabIdx - 1].SetActive(showGlowEffect);
else
answersRedHaloEffects[prefabIdx - 1].SetActive(showGlowEffect);
}
/// <summary>
@@ -244,22 +247,35 @@ public class Quiz2Controller : MonoBehaviour {
}
/// <summary>
/// Adds Halo prefabs to all answers
/// Adds red Halo prefabs to all answers
/// </summary>
private void InstantiateHaloPrefabs()
private void InstantiateRedHaloPrefabs()
{
for (int i = 0; i < answers.Count; i++)
{
GameObject answerPrefab = Instantiate(haloEffect) as GameObject;
GameObject answerPrefab = Instantiate(haloEffectRed) as GameObject;
answerPrefab.SetActive(false);
answerPrefab.transform.SetParent(answers[i].transform, false);
answersHaloEffects.Add(answerPrefab);
answersRedHaloEffects.Add(answerPrefab);
}
}
/// <summary>
/// Adds red Halo prefabs to all answers
/// </summary>
private void InstantiateGreenHaloPrefabs()
{
for (int i = 0; i < answers.Count; i++)
{
GameObject answerPrefab = Instantiate(haloEffectGreen) as GameObject;
answerPrefab.SetActive(false);
answerPrefab.transform.SetParent(answers[i].transform, false);
answersGreenHaloEffects.Add(answerPrefab);
}
}
void LoadNextPair()
{
counterPerQuestionValue = 0;
counterDisplayAnswersValue = 0;
counterDisplayAnswersStarted = false;
ClearCurrentSceneGlowEffect();