Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Image blackScreen;
- public Image menuPanel;
- private bool pleaseOpenMenu;
- private bool pleaseCloseMenu;
- void Update () {
- // PLEASE OPEN / CLOSE MENU PHASE 1
- if (pleaseOpenMenu == true && blackScreen.color.a > 0.95f)
- {
- blackScreen.gameObject.SetActive(true);
- menuPanel.gameObject.SetActive(true);
- StartCoroutine(FadeImage(blackScreen, true));
- }
- if (pleaseCloseMenu == true && blackScreen.color.a > 0.95f)
- {
- StartCoroutine(FadeImage(blackScreen, true));
- pleaseCloseMenu = false;
- }
- // PLEASE OPEN/CLOSE MENU PHASE 2
- if (pleaseOpenMenu == true && blackScreen.color.a < 0.01f)
- {
- blackScreen.gameObject.SetActive(false);
- pleaseOpenMenu = false;
- }
- if (pleaseCloseMenu == true && blackScreen.color.a < 0.01f)
- {
- blackScreen.gameObject.SetActive(false);
- menuPanel.gameObject.SetActive(false);
- pleaseCloseMenu = false;
- }
- }
- public void OpenMenu ()
- {
- blackScreen.color = new Color(255, 255, 255, 0.02f);
- blackScreen.gameObject.SetActive(true);
- StartCoroutine(FadeImage(blackScreen, false));
- pleaseOpenMenu = true;
- }
- public void CloseMenu ()
- {
- blackScreen.color = new Color(255, 255, 255, 0.02f);
- blackScreen.gameObject.SetActive(true);
- StartCoroutine(FadeImage(blackScreen, false));
- pleaseCloseMenu = true;
- }
- IEnumerator FadeImage(Image img, bool fadeAway)
- {
- if (fadeAway)
- {
- for (float i = 1f; i >= 0f; i -= Time.deltaTime)
- {
- img.color = new Color(0, 0, 0, i);
- yield return null;
- }
- }
- else
- {
- for (float i = 0f; i <= 1f; i += Time.deltaTime)
- {
- img.color = new Color(0, 0, 0, i);
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement