Glow u igrici parovi
This commit is contained in:
@@ -519,7 +519,7 @@ MonoBehaviour:
|
|||||||
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
|
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
|
||||||
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
||||||
m_FontData:
|
m_FontData:
|
||||||
m_Font: {fileID: 12800000, guid: ea60ddb36cd742f43afccf15d3ffe272, type: 3}
|
m_Font: {fileID: 12800000, guid: 34b69fa3cc23fa1498ecdf2650846c9d, type: 3}
|
||||||
m_FontSize: 70
|
m_FontSize: 70
|
||||||
m_FontStyle: 0
|
m_FontStyle: 0
|
||||||
m_BestFit: 0
|
m_BestFit: 0
|
||||||
|
|||||||
@@ -876,6 +876,7 @@ MonoBehaviour:
|
|||||||
- {fileID: 1326664960808868, guid: 29eeb6bf5cef40942abd867490425eb6, type: 2}
|
- {fileID: 1326664960808868, guid: 29eeb6bf5cef40942abd867490425eb6, type: 2}
|
||||||
- {fileID: 1476576601628434, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
|
- {fileID: 1476576601628434, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
|
||||||
- {fileID: 1283141416758514, guid: e4cb59c48e25ba84a945d869e623f641, type: 2}
|
- {fileID: 1283141416758514, guid: e4cb59c48e25ba84a945d869e623f641, type: 2}
|
||||||
|
haloEffect: {fileID: 1264499954100932, guid: 6ead2541b42799549a0f85e8d7a8305f, type: 2}
|
||||||
--- !u!1001 &1451760075
|
--- !u!1001 &1451760075
|
||||||
Prefab:
|
Prefab:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -13,9 +13,14 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
|
|
||||||
public GameObject[] answerModels;
|
public GameObject[] answerModels;
|
||||||
|
|
||||||
|
public GameObject haloEffect;
|
||||||
|
|
||||||
// References to answers
|
// References to answers
|
||||||
private List<GameObject> answers;
|
private List<GameObject> answers;
|
||||||
|
|
||||||
|
// References to answers halo prefabs
|
||||||
|
private List<GameObject> answersHaloEffects;
|
||||||
|
|
||||||
private const int numberOfAnswers = 2;
|
private const int numberOfAnswers = 2;
|
||||||
|
|
||||||
private const int scoreCorrectAnswer = 10;
|
private const int scoreCorrectAnswer = 10;
|
||||||
@@ -30,7 +35,7 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
|
|
||||||
private int scoreValue;
|
private int scoreValue;
|
||||||
|
|
||||||
private int questionIdx = 0;
|
private int questionIdx;
|
||||||
|
|
||||||
private float counterValue;
|
private float counterValue;
|
||||||
|
|
||||||
@@ -38,6 +43,12 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
|
|
||||||
private int selectedAnswerIdx;
|
private int selectedAnswerIdx;
|
||||||
|
|
||||||
|
private const int counterDisplayAnswersTotalValue = 3;
|
||||||
|
|
||||||
|
private float counterDisplayAnswersValue;
|
||||||
|
|
||||||
|
private bool counterDisplayAnswersStarted = false;
|
||||||
|
|
||||||
// Positions for answers 1, 2, 3 and 4
|
// Positions for answers 1, 2, 3 and 4
|
||||||
private Vector3[] answerPositions = new Vector3[]
|
private Vector3[] answerPositions = new Vector3[]
|
||||||
{
|
{
|
||||||
@@ -114,36 +125,48 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
|
// Init counters and score
|
||||||
|
questionIdx = 0;
|
||||||
scoreValue = 0;
|
scoreValue = 0;
|
||||||
counterValue = 0;
|
counterValue = 0;
|
||||||
counterPerQuestionValue = 0;
|
counterPerQuestionValue = 0;
|
||||||
|
counterDisplayAnswersValue = 0;
|
||||||
|
counterDisplayAnswersStarted = false;
|
||||||
totalTimePerQuestion = totalGameTime / questions.Count;
|
totalTimePerQuestion = totalGameTime / questions.Count;
|
||||||
answers = new List<GameObject>();
|
answers = new List<GameObject>();
|
||||||
|
answersHaloEffects = new List<GameObject>();
|
||||||
UpdateCounter();
|
UpdateCounter();
|
||||||
UpdateScore();
|
UpdateScore(true);
|
||||||
InstantiateAnswers();
|
InstantiateAnswers();
|
||||||
|
InstantiateHaloPrefabs();
|
||||||
UpdateScene();
|
UpdateScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update () {
|
void Update ()
|
||||||
|
{
|
||||||
// TODO: Game over
|
Debug.Log(counterDisplayAnswersValue.ToString());
|
||||||
|
// Main counter
|
||||||
|
// Game over
|
||||||
if (counterValue > totalGameTime)
|
if (counterValue > totalGameTime)
|
||||||
SceneManager.LoadScene("EntryScene");
|
SceneManager.LoadScene("EntryScene");
|
||||||
counterValue += Time.deltaTime;
|
counterValue += Time.deltaTime;
|
||||||
|
|
||||||
UpdateCounter();
|
UpdateCounter();
|
||||||
|
|
||||||
// Next pair
|
// Load next pair
|
||||||
if(counterPerQuestionValue > totalTimePerQuestion)
|
if((counterDisplayAnswersValue > counterDisplayAnswersTotalValue) && counterDisplayAnswersStarted || (counterPerQuestionValue > totalTimePerQuestion && !counterDisplayAnswersStarted))
|
||||||
{
|
{
|
||||||
counterPerQuestionValue = 0;
|
// Load next pair
|
||||||
LoadNextPair();
|
LoadNextPair();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (counterDisplayAnswersValue < counterDisplayAnswersTotalValue && counterDisplayAnswersStarted)
|
||||||
|
counterDisplayAnswersValue += Time.deltaTime;
|
||||||
|
|
||||||
|
if (counterPerQuestionValue < totalTimePerQuestion)
|
||||||
counterPerQuestionValue += Time.deltaTime;
|
counterPerQuestionValue += Time.deltaTime;
|
||||||
|
|
||||||
|
|
||||||
// Select answers event handler
|
// Select answers event handler
|
||||||
if (Input.GetMouseButtonDown(0))
|
if (Input.GetMouseButtonDown(0))
|
||||||
{
|
{
|
||||||
@@ -152,15 +175,40 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
|
|
||||||
if (Physics.Raycast(ray, out hit, 100))
|
if (Physics.Raycast(ray, out hit, 100))
|
||||||
{
|
{
|
||||||
Debug.Log(hit.transform.gameObject.name);
|
if (counterDisplayAnswersStarted)
|
||||||
|
return;
|
||||||
|
// Debug.Log(hit.transform.gameObject.name);
|
||||||
|
counterDisplayAnswersStarted = true;
|
||||||
|
// Set glow
|
||||||
selectedAnswerIdx = GetAnswerIdx(hit.transform.gameObject.name);
|
selectedAnswerIdx = GetAnswerIdx(hit.transform.gameObject.name);
|
||||||
counterPerQuestionValue = 0;
|
SetGlowEffect(selectedAnswerIdx, true);
|
||||||
LoadNextPair();
|
// Update score
|
||||||
|
UpdateScore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clears glow from all currently shown answers
|
||||||
|
/// </summary>
|
||||||
|
private void ClearCurrentSceneGlowEffect()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < numberOfAnswers; i++)
|
||||||
|
{
|
||||||
|
int prefabIdx = questionIdx * numberOfAnswers + i;
|
||||||
|
answersHaloEffects[prefabIdx].SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiates all answer objects
|
/// Instantiates all answer objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -195,12 +243,26 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
answers.Add(answerGameObject);
|
answers.Add(answerGameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds Halo prefabs to all answers
|
||||||
|
/// </summary>
|
||||||
|
private void InstantiateHaloPrefabs()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < answers.Count; i++)
|
||||||
|
{
|
||||||
|
GameObject answerPrefab = Instantiate(haloEffect) as GameObject;
|
||||||
|
answerPrefab.SetActive(false);
|
||||||
|
answerPrefab.transform.SetParent(answers[i].transform, false);
|
||||||
|
answersHaloEffects.Add(answerPrefab);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LoadNextPair()
|
void LoadNextPair()
|
||||||
{
|
{
|
||||||
scoreValue += GetScore();
|
counterPerQuestionValue = 0;
|
||||||
if (scoreValue < 0)
|
counterDisplayAnswersValue = 0;
|
||||||
scoreValue = 0;
|
counterDisplayAnswersStarted = false;
|
||||||
UpdateScore();
|
ClearCurrentSceneGlowEffect();
|
||||||
questionIdx = questionIdx + 1;
|
questionIdx = questionIdx + 1;
|
||||||
if (questionIdx == questions.Count)
|
if (questionIdx == questions.Count)
|
||||||
SceneManager.LoadScene("EntryScene");
|
SceneManager.LoadScene("EntryScene");
|
||||||
@@ -211,8 +273,14 @@ public class Quiz2Controller : MonoBehaviour {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates score value - called from Update() method
|
/// Updates score value - called from Update() method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateScore()
|
private void UpdateScore(bool initialization = false)
|
||||||
{
|
{
|
||||||
|
if (!initialization)
|
||||||
|
{
|
||||||
|
scoreValue += GetScore();
|
||||||
|
if (scoreValue < 0)
|
||||||
|
scoreValue = 0;
|
||||||
|
}
|
||||||
scoreText.text = scoreValue.ToString();
|
scoreText.text = scoreValue.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ public class Quiz4Controller : MonoBehaviour {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InstantiateHaloPrefabs()
|
private void InstantiateHaloPrefabs()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < answers.Count(); i++)
|
for (int i = 0; i < answers.Count; i++)
|
||||||
{
|
{
|
||||||
GameObject answerPrefab = Instantiate(haloEffect) as GameObject;
|
GameObject answerPrefab = Instantiate(haloEffect) as GameObject;
|
||||||
answerPrefab.SetActive(false);
|
answerPrefab.SetActive(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user