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.

64 lines
1.5 KiB

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