Advertisement
Guest User

fullscript

a guest
Jan 15th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.45 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Flake
  6. {
  7.     public Sprite sprite;
  8.  
  9.     public int col { get; set; }
  10.     public int row { get; set; }
  11.     public float alpha { get; set; }
  12.     public Vector2 pos { get; set; }
  13.     public float scale { get; set; }
  14.     public Vector2 velocity { get; set; }
  15.  
  16.     SpriteRenderer flakeRenderer;
  17.     GameObject menuObject;
  18.  
  19.     Transform t;
  20.  
  21.  
  22.     public Flake(Sprite spr, int c, int r, float a, Vector2 p, float s, Vector2 v)
  23.     {
  24.         //menuObject = GameObject.Find("MenuBackGround");
  25.         //flakeRenderer = menuObject.GetComponent<SpriteRenderer>();
  26.  
  27.         string n = "flakes_" + spr.ToString();
  28.         sprite = spr;
  29.  
  30.         //flakeRenderer.sprite = sprite;
  31.         col = c;
  32.         row = r;
  33.         alpha = a;
  34.         pos = p;
  35.         scale = s;
  36.         velocity = v;
  37.     }
  38.  
  39.     public void Update(float elapsed)
  40.     {
  41.  
  42.         if (sprite == null)
  43.             Debug.Log("null sprite!");
  44.  
  45.  
  46.         alpha -= 45 * elapsed;
  47.         alpha = Mathf.Clamp(alpha, 0, 255);
  48.  
  49.         scale -= 0.055f * elapsed;
  50.         scale = Mathf.Clamp(scale, 0, 2.0f);
  51.  
  52.         pos += velocity * elapsed;
  53.  
  54.         t.localPosition = new Vector3(pos.x, 0, pos.y);
  55.     }
  56.  
  57. }
  58.  
  59. public class mainMenu : MonoBehaviour
  60. {
  61.     SpriteRenderer fr;
  62.     public Sprite[] sprites;
  63.  
  64.     enum MenuState
  65.     {
  66.         fadeIn,
  67.         menu,
  68.     };
  69.  
  70.  
  71.     MenuState menuState = MenuState.fadeIn;
  72.  
  73.     GameObject subtext;
  74.     GameObject titleLogo;
  75.     GameObject start;
  76.  
  77.     float startAlpha = 0;
  78.     float titleAlpha = 0;
  79.     float subAlpha = 0;
  80.  
  81.     Color theColor;
  82.  
  83.     List<Flake> flakeList = new List<Flake>();
  84.     float flakeTimer = 0.0f;
  85.     float flakeDelay = 0.075f;
  86.  
  87.     public static bool FadeTitle { get; set; }
  88.     int titleFadeDir = 1;
  89.  
  90.     public int flakeCount = 0;
  91.     public int flakeSpriteCount = 0;
  92.  
  93.     // Use this for initialization
  94.     void Start ()
  95.     {
  96.         fr = GetComponent<SpriteRenderer>();
  97.  
  98.         start = GameObject.Find("start");
  99.         start.renderer.material.color = new Color(1, 1, 1, startAlpha);
  100.        
  101.         subtext = GameObject.Find("subtext");
  102.         subtext.renderer.material.color = new Color(1, 1, 1, subAlpha);
  103.  
  104.         titleLogo = GameObject.Find("titlenosnow");
  105.         titleLogo.renderer.material.color = new Color(1, 1, 1, titleAlpha);
  106.  
  107.         sprites = Resources.LoadAll<Sprite>("Flakes");
  108.  
  109.         flakeList.Add(new Flake(this.sprites[Random.Range(0, this.sprites.GetLength(0) - 1)], 0, 0, 1, new Vector2(1, 1), 1, new Vector2(1, 1)));
  110.         flakeSpriteCount = sprites.GetLength(0);
  111.     }
  112.    
  113.     // Update is called once per frame
  114.     void Update ()
  115.     {
  116.         float elapsed = Time.deltaTime;
  117.  
  118.         #region handle falling snow
  119.  
  120.         flakeTimer += Time.deltaTime;
  121.  
  122.         if (flakeTimer > flakeDelay)
  123.         {
  124.             // add a flake
  125.             flakeTimer = 0.0f;
  126.             flakeList.Add(new Flake(this.sprites[Random.Range(0, this.sprites.GetLength(0) - 1)], (int)helpers.RandomBetween(0, 3), (int)helpers.RandomBetween(0, 4), helpers.RandomBetween(127, 255), new Vector2(helpers.RandomBetween(40, 1240), -75), helpers.RandomBetween(0.75f, 1.25f), new Vector2(helpers.RandomBetween(-20, 20), helpers.RandomBetween(30, 150))));
  127.         }
  128.  
  129.         flakeCount = flakeList.Count;
  130.  
  131.         int index = 0;
  132.         while (index < flakeList.Count)
  133.         {
  134.             flakeList[index].Update(elapsed);
  135.  
  136.             if (flakeList[index].pos.y > 600)
  137.             {
  138.                 flakeList.RemoveAt(index);
  139.             }
  140.             else
  141.                 index++;
  142.         }
  143.  
  144.  
  145.  
  146.         #endregion
  147.  
  148.  
  149.         if (menuState == MenuState.fadeIn)
  150.         {
  151.             titleAlpha += Time.deltaTime * 1.5f;
  152.             theColor = new Color(1, 1, 1, titleAlpha);
  153.             titleLogo.renderer.material.color = theColor;
  154.  
  155.             if(titleAlpha > 0.35f)
  156.             {
  157.                 subAlpha += Time.deltaTime * 2f;
  158.                 theColor = new Color(1, 1, 1, subAlpha);
  159.                 subtext.renderer.material.color = theColor;
  160.  
  161.                 if(subAlpha > 0.75f)
  162.                 {
  163.                     startAlpha += Time.deltaTime * 2f;
  164.                     theColor = new Color(1, 1, 1, startAlpha);
  165.                     start.renderer.material.color = theColor;
  166.                 }
  167.             }
  168.  
  169.             titleAlpha = Mathf.Clamp(titleAlpha, 0f, 1f);
  170.             subAlpha = Mathf.Clamp(subAlpha, 0f, 1f);
  171.             startAlpha = Mathf.Clamp(startAlpha, 0f, 1f);
  172.  
  173.             if(titleAlpha > 0.95f && subAlpha > 0.95f && startAlpha > 0.95f)
  174.             {
  175.                 theColor = new Color(1, 1, 1, 1);
  176.                 subtext.renderer.material.color = theColor;
  177.                 titleLogo.renderer.material.color = theColor;
  178.                 start.renderer.material.color = theColor;
  179.             }
  180.  
  181.             if(Input.anyKeyDown || Input.GetMouseButtonDown(0))
  182.             {
  183.                 menuState = MenuState.menu;
  184.             }
  185.            
  186.         }
  187.  
  188.  
  189.         if (menuState == MenuState.menu)
  190.         {
  191.             subAlpha = Mathf.Clamp(subAlpha, 0, 1f);
  192.  
  193.             if(subAlpha > 0)
  194.             {
  195.                 subAlpha -= Time.deltaTime * 4f;
  196.                 theColor = new Color(1, 1, 1, subAlpha);
  197.                 subtext.renderer.material.color = theColor;
  198.                 start.renderer.material.color = theColor;
  199.             }
  200.         }
  201.  
  202.     }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement