Advertisement
kasru

Fade Gui

Jan 20th, 2013
4,491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //****** Donations are greatly appreciated.  ******
  2. //****** You can donate directly to Jesse through paypal at  https://www.paypal.me/JEtzler   ******
  3.  
  4. function Update () {
  5.  
  6. }
  7.  
  8. // FadeInOut
  9. //
  10. //--------------------------------------------------------------------
  11. //                        Public parameters
  12. //--------------------------------------------------------------------
  13.  
  14. public var fadeOutTexture : Texture2D;
  15. public var fadeSpeed = 2.0;
  16. var drawDepth = -1000;
  17. var alphaWait : boolean = true;
  18.  
  19. //--------------------------------------------------------------------
  20. //                       Private variables
  21. //--------------------------------------------------------------------
  22.  
  23. private var alpha = 1.0;
  24. private var fadeDir = -1;
  25.  
  26. //--------------------------------------------------------------------
  27. //                       Runtime functions
  28. //--------------------------------------------------------------------
  29.  
  30. //--------------------------------------------------------------------
  31.  
  32. function OnGUI(){
  33.  
  34.    if(alphaWait == false) {
  35.    
  36.     alpha += fadeDir * fadeSpeed * Time.deltaTime;
  37.     }
  38.    
  39.     alpha = Mathf.Clamp01(alpha);    
  40.     GUI.color.a = alpha;  
  41.     GUI.depth = drawDepth;  
  42.     GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
  43. }
  44.  
  45. //--------------------------------------------------------------------
  46.  
  47. function fadeIn(){
  48.  
  49.     yield WaitForSeconds(2);
  50.     alphaWait = false;
  51.     fadeDir = -1;  
  52. }
  53.  
  54. //--------------------------------------------------------------------
  55.  
  56. function fadeOut(){
  57.     fadeDir = 1;  
  58. }
  59.  
  60. function Start(){  
  61.     alpha=1;
  62.     fadeIn();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement