SkipAndLoad.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. public class SkipAndLoad : MonoBehaviour
  5. {
  6. [SerializeField]
  7. private UIButton _skip;
  8. [SerializeField]
  9. private UISprite _progres;
  10. private AsyncOperation _async;
  11. void Start ()
  12. {
  13. _skip.onClick.Add(new EventDelegate(Skip));
  14. Show();
  15. }
  16. private void Update()
  17. {
  18. if (_async != null)
  19. {
  20. _progres.fillAmount = _async.progress;
  21. }
  22. }
  23. public void Show()
  24. {
  25. StartCoroutine(_routine());
  26. _progres.transform.parent.gameObject.SetActive(false);
  27. _skip.gameObject.SetActive(true);
  28. }
  29. private IEnumerator _routine()
  30. {
  31. yield return new WaitForSeconds(5);
  32. Load();
  33. }
  34. private void Skip()
  35. {
  36. Load();
  37. }
  38. private void Load()
  39. {
  40. if (!_skip.gameObject.activeSelf)
  41. {
  42. return;
  43. }
  44. _skip.gameObject.SetActive(false);
  45. StartCoroutine(_show());
  46. }
  47. private IEnumerator _show()
  48. {
  49. _progres.transform.parent.gameObject.SetActive(true);
  50. _skip.gameObject.SetActive(false);
  51. _async = SceneManager.LoadSceneAsync("Santa");
  52. yield return _async;
  53. }
  54. }