You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

4 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using JetBrains.Annotations;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7. public class GameStateController : MonoBehaviour
  8. {
  9. public Canvas WinLose;
  10. public GameObject WinText;
  11. public GameObject LoseText;
  12. public AudioClip WinClip;
  13. public AudioClip LoseClip;
  14. public AudioSource source;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. source = GetComponent<AudioSource>();
  19. }
  20. public void WinState()
  21. {
  22. source.clip = WinClip;
  23. source.Play();
  24. StartCoroutine(FadeImage(WinLose.GetComponentInChildren<Image>()));
  25. WinText.SetActive(true);
  26. StartCoroutine(WaitForLoadOut());
  27. }
  28. public void LoseState()
  29. {
  30. Debug.Log("Lose");
  31. source.clip = LoseClip;
  32. source.Play();
  33. StartCoroutine(FadeImage(WinLose.GetComponentInChildren<Image>()));
  34. LoseText.SetActive(true);
  35. StartCoroutine(WaitForLoadOut());
  36. }
  37. public IEnumerator FadeImage(Image img)
  38. {
  39. for (float i = 0; i <= 1; i += Time.deltaTime)
  40. {
  41. img.color = new Color(0, 0, 0, i);
  42. yield return null;
  43. }
  44. }
  45. public IEnumerator WaitForLoadOut()
  46. {
  47. yield return new WaitForSeconds(5.0f);
  48. SceneManager.LoadScene(0);
  49. }
  50. // Update is called once per frame
  51. void Update()
  52. {
  53. }
  54. }