Browse Source

showing right answers

A
Josh 2 years ago
parent
commit
11e1099e59
  1. 11
      namedropper/Assets/Scripts/Category.cs
  2. 4
      namedropper/Assets/Scripts/Game.cs
  3. 7
      namedropper/Assets/Scripts/Player.cs

11
namedropper/Assets/Scripts/Category.cs

@ -5,6 +5,7 @@ using UnityEngine.UI;
public class Category : MonoBehaviour public class Category : MonoBehaviour
{ {
const bool SHOW_RIGHT_ANSWERS = true;
public string Name; public string Name;
public List<string> Elements = new List<string>(); public List<string> Elements = new List<string>();
List<string> WorkingElements = new List<string>(); List<string> WorkingElements = new List<string>();
@ -28,15 +29,23 @@ public class Category : MonoBehaviour
_streak.SetActive(true); _streak.SetActive(true);
_streak.GetComponent<TMPro.TMP_Text>().text = "10"; _streak.GetComponent<TMPro.TMP_Text>().text = "10";
_streak.GetComponent<TMPro.TMP_Text>().color = Color.green;
if (streak > 1) if (streak > 1)
{ {
_streak.GetComponent<TMPro.TMP_Text>().text += " x " + streak; _streak.GetComponent<TMPro.TMP_Text>().text += " x " + streak;
} }
} }
public void ShowFeedbackBad() public void ShowFeedbackBad(string wrongAnswer)
{ {
ShowFeedback(_feedbackBad); ShowFeedback(_feedbackBad);
if (SHOW_RIGHT_ANSWERS)
{
_streak.SetActive(true);
_streak.GetComponent<TMPro.TMP_Text>().text = wrongAnswer;
_streak.GetComponent<TMPro.TMP_Text>().color = Color.red;
}
} }
void ShowFeedback(SpriteRenderer feedback, bool show = true) void ShowFeedback(SpriteRenderer feedback, bool show = true)

4
namedropper/Assets/Scripts/Game.cs

@ -214,10 +214,10 @@ public class Game : MonoBehaviour
UpdateScores(); UpdateScores();
} }
public string PickRandomWord() public System.Tuple<string,string> PickRandomWord()
{ {
int index = Random.Range(0, _categories.Length); int index = Random.Range(0, _categories.Length);
return _categories[index].PickRandomWord(); return new System.Tuple<string, string>(_categories[index].Name, _categories[index].PickRandomWord());
} }
public void UpdateScores() public void UpdateScores()

7
namedropper/Assets/Scripts/Player.cs

@ -28,6 +28,7 @@ public class Player : MonoBehaviour
GameObject _spriteChildTop; GameObject _spriteChildTop;
Vector3 _originalScale; Vector3 _originalScale;
Vector3 _originalTextScale; Vector3 _originalTextScale;
string _categoryName;
public enum Team public enum Team
{ {
@ -118,7 +119,9 @@ public class Player : MonoBehaviour
{ {
if (_game != null) if (_game != null)
{ {
_text.text = _game.PickRandomWord(); System.Tuple<string, string> tuple = _game.PickRandomWord();
_categoryName = tuple.Item1;
_text.text = tuple.Item2;
SetRandomTextRotation(); SetRandomTextRotation();
SetFont(); SetFont();
} }
@ -193,7 +196,7 @@ public class Player : MonoBehaviour
else else
{ {
_streak = 0; _streak = 0;
category.ShowFeedbackBad(); category.ShowFeedbackBad(_categoryName);
this.gameObject.SetActive(false); this.gameObject.SetActive(false);
Respawn(); Respawn();
//Invoke("Respawn", 2f); //Invoke("Respawn", 2f);

Loading…
Cancel
Save