Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. [RequireComponent(typeof(AudioSource))]
  7. public class Reader : MonoBehaviour
  8. {
  9. private GameManager gm;
  10.  
  11. public Text text;
  12. public Question question;
  13. private AudioSource _audio;
  14.  
  15. private void Start()
  16. {
  17. gm = GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>();
  18. _audio = GetComponent<AudioSource>();
  19. }
  20. private void Update()
  21. {
  22. if (question != null)
  23. {
  24. text.text = question.answer.ToString();
  25. _audio.PlayOneShot(gm.correctAnswer.GetComponent<AudioSource>().Play());
  26. }
  27. }
  28.  
  29. public void CheckAnswer()
  30. {
  31. if (transform.gameObject != gm.correctAnswer.transform.gameObject)
  32. {
  33. transform.GetComponent<Image>().color = Color.red;
  34. }
  35.  
  36. gm.correctAnswer.GetComponent<Image>().color = Color.green;
  37.  
  38. foreach (Button btn in gm.options)
  39. {
  40. btn.GetComponent<Button>().interactable = false;
  41. }
  42.  
  43. gm.correctAnswer.GetComponent<Button>().interactable = false;
  44.  
  45. StartCoroutine(gm.NewRound());
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement