Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1.     public Image blackScreen;
  2.     public Image menuPanel;
  3.  
  4.     private bool pleaseOpenMenu;
  5.     private bool pleaseCloseMenu;
  6.    
  7.     void Update () {
  8.        
  9.  
  10.         // PLEASE OPEN / CLOSE MENU  PHASE 1
  11.         if (pleaseOpenMenu == true && blackScreen.color.a > 0.95f)
  12.         {
  13.             blackScreen.gameObject.SetActive(true);
  14.             menuPanel.gameObject.SetActive(true);
  15.             StartCoroutine(FadeImage(blackScreen, true));
  16.            
  17.         }
  18.         if (pleaseCloseMenu == true && blackScreen.color.a > 0.95f)
  19.         {
  20.             StartCoroutine(FadeImage(blackScreen, true));
  21.             pleaseCloseMenu = false;
  22.         }
  23.  
  24.         // PLEASE OPEN/CLOSE MENU PHASE 2
  25.         if (pleaseOpenMenu == true && blackScreen.color.a < 0.01f)
  26.         {
  27.             blackScreen.gameObject.SetActive(false);
  28.             pleaseOpenMenu = false;
  29.         }
  30.         if (pleaseCloseMenu == true && blackScreen.color.a < 0.01f)
  31.         {
  32.             blackScreen.gameObject.SetActive(false);
  33.             menuPanel.gameObject.SetActive(false);
  34.             pleaseCloseMenu = false;
  35.         }
  36.  
  37.  
  38.     }
  39.  
  40.     public void OpenMenu ()
  41.     {
  42.         blackScreen.color = new Color(255, 255, 255, 0.02f);
  43.         blackScreen.gameObject.SetActive(true);
  44.         StartCoroutine(FadeImage(blackScreen, false));
  45.         pleaseOpenMenu = true;
  46.        
  47.     }
  48.  
  49.     public void CloseMenu ()
  50.     {
  51.         blackScreen.color = new Color(255, 255, 255, 0.02f);
  52.         blackScreen.gameObject.SetActive(true);
  53.         StartCoroutine(FadeImage(blackScreen, false));
  54.         pleaseCloseMenu = true;
  55.     }
  56.  
  57.  
  58.     IEnumerator FadeImage(Image img, bool fadeAway)
  59.     {
  60.         if (fadeAway)
  61.         {
  62.             for (float i = 1f; i >= 0f; i -= Time.deltaTime)
  63.             {
  64.                 img.color = new Color(0, 0, 0, i);
  65.                 yield return null;
  66.             }
  67.  
  68.         }
  69.         else
  70.         {
  71.             for (float i = 0f; i <= 1f; i += Time.deltaTime)
  72.             {
  73.                 img.color = new Color(0, 0, 0, i);
  74.                 yield return null;
  75.             }
  76.         }
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement