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. SceneManager.LoadScene(0);
  28. }
  29. public void LoseState()
  30. {
  31. Debug.Log("Lose");
  32. source.clip = LoseClip;
  33. source.Play();
  34. StartCoroutine(FadeImage(WinLose.GetComponentInChildren<Image>()));
  35. LoseText.SetActive(true);
  36. StartCoroutine(WaitForLoadOut());
  37. SceneManager.LoadScene(0);
  38. }
  39. public IEnumerator FadeImage(Image img)
  40. {
  41. for (float i = 0; i <= 1; i += Time.deltaTime)
  42. {
  43. img.color = new Color(0, 0, 0, i);
  44. yield return null;
  45. }
  46. }
  47. public IEnumerator WaitForLoadOut()
  48. {
  49. yield return new WaitForSeconds(5.0f);
  50. }
  51. // Update is called once per frame
  52. void Update()
  53. {
  54. }
  55. }