Global Game Jam 2022
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.

77 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. public class HowToPlayController : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private MaskableGraphic[] graphics;
  11. [SerializeField]
  12. private float fadeTime = 1.0f;
  13. [SerializeField]
  14. private float showTime = 3;
  15. [SerializeField]
  16. private string NextLevel = "Level 1";
  17. IEnumerator Start()
  18. {
  19. float elapsedTime = 0;
  20. Color color;
  21. while (elapsedTime < fadeTime)
  22. {
  23. foreach(MaskableGraphic g in graphics)
  24. {
  25. color = g.color;
  26. color.a = elapsedTime / fadeTime;
  27. g.color = color;
  28. yield return new WaitForEndOfFrame();
  29. elapsedTime += Time.deltaTime;
  30. }
  31. }
  32. foreach (MaskableGraphic g in graphics)
  33. {
  34. color = g.color;
  35. color.a = 1;
  36. g.color = color;
  37. }
  38. yield return new WaitForSeconds(showTime);
  39. elapsedTime = 0;
  40. while (elapsedTime < fadeTime)
  41. {
  42. foreach (MaskableGraphic g in graphics)
  43. {
  44. color = g.color;
  45. color.a = 1 - elapsedTime / fadeTime;
  46. g.color = color;
  47. yield return new WaitForEndOfFrame();
  48. elapsedTime += Time.deltaTime;
  49. }
  50. }
  51. foreach (MaskableGraphic g in graphics)
  52. {
  53. color = g.color;
  54. color.a = 0;
  55. g.color = color;
  56. }
  57. SceneManager.LoadScene(NextLevel);
  58. }
  59. }