Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class Flake
- {
- public Sprite sprite;
- public int col { get; set; }
- public int row { get; set; }
- public float alpha { get; set; }
- public Vector2 pos { get; set; }
- public float scale { get; set; }
- public Vector2 velocity { get; set; }
- SpriteRenderer flakeRenderer;
- GameObject menuObject;
- Transform t;
- public Flake(Sprite spr, int c, int r, float a, Vector2 p, float s, Vector2 v)
- {
- //menuObject = GameObject.Find("MenuBackGround");
- //flakeRenderer = menuObject.GetComponent<SpriteRenderer>();
- string n = "flakes_" + spr.ToString();
- sprite = spr;
- //flakeRenderer.sprite = sprite;
- col = c;
- row = r;
- alpha = a;
- pos = p;
- scale = s;
- velocity = v;
- }
- public void Update(float elapsed)
- {
- if (sprite == null)
- Debug.Log("null sprite!");
- alpha -= 45 * elapsed;
- alpha = Mathf.Clamp(alpha, 0, 255);
- scale -= 0.055f * elapsed;
- scale = Mathf.Clamp(scale, 0, 2.0f);
- pos += velocity * elapsed;
- t.localPosition = new Vector3(pos.x, 0, pos.y);
- }
- }
- public class mainMenu : MonoBehaviour
- {
- SpriteRenderer fr;
- public Sprite[] sprites;
- enum MenuState
- {
- fadeIn,
- menu,
- };
- MenuState menuState = MenuState.fadeIn;
- GameObject subtext;
- GameObject titleLogo;
- GameObject start;
- float startAlpha = 0;
- float titleAlpha = 0;
- float subAlpha = 0;
- Color theColor;
- List<Flake> flakeList = new List<Flake>();
- float flakeTimer = 0.0f;
- float flakeDelay = 0.075f;
- public static bool FadeTitle { get; set; }
- int titleFadeDir = 1;
- public int flakeCount = 0;
- public int flakeSpriteCount = 0;
- // Use this for initialization
- void Start ()
- {
- fr = GetComponent<SpriteRenderer>();
- start = GameObject.Find("start");
- start.renderer.material.color = new Color(1, 1, 1, startAlpha);
- subtext = GameObject.Find("subtext");
- subtext.renderer.material.color = new Color(1, 1, 1, subAlpha);
- titleLogo = GameObject.Find("titlenosnow");
- titleLogo.renderer.material.color = new Color(1, 1, 1, titleAlpha);
- sprites = Resources.LoadAll<Sprite>("Flakes");
- 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)));
- flakeSpriteCount = sprites.GetLength(0);
- }
- // Update is called once per frame
- void Update ()
- {
- float elapsed = Time.deltaTime;
- #region handle falling snow
- flakeTimer += Time.deltaTime;
- if (flakeTimer > flakeDelay)
- {
- // add a flake
- flakeTimer = 0.0f;
- 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))));
- }
- flakeCount = flakeList.Count;
- int index = 0;
- while (index < flakeList.Count)
- {
- flakeList[index].Update(elapsed);
- if (flakeList[index].pos.y > 600)
- {
- flakeList.RemoveAt(index);
- }
- else
- index++;
- }
- #endregion
- if (menuState == MenuState.fadeIn)
- {
- titleAlpha += Time.deltaTime * 1.5f;
- theColor = new Color(1, 1, 1, titleAlpha);
- titleLogo.renderer.material.color = theColor;
- if(titleAlpha > 0.35f)
- {
- subAlpha += Time.deltaTime * 2f;
- theColor = new Color(1, 1, 1, subAlpha);
- subtext.renderer.material.color = theColor;
- if(subAlpha > 0.75f)
- {
- startAlpha += Time.deltaTime * 2f;
- theColor = new Color(1, 1, 1, startAlpha);
- start.renderer.material.color = theColor;
- }
- }
- titleAlpha = Mathf.Clamp(titleAlpha, 0f, 1f);
- subAlpha = Mathf.Clamp(subAlpha, 0f, 1f);
- startAlpha = Mathf.Clamp(startAlpha, 0f, 1f);
- if(titleAlpha > 0.95f && subAlpha > 0.95f && startAlpha > 0.95f)
- {
- theColor = new Color(1, 1, 1, 1);
- subtext.renderer.material.color = theColor;
- titleLogo.renderer.material.color = theColor;
- start.renderer.material.color = theColor;
- }
- if(Input.anyKeyDown || Input.GetMouseButtonDown(0))
- {
- menuState = MenuState.menu;
- }
- }
- if (menuState == MenuState.menu)
- {
- subAlpha = Mathf.Clamp(subAlpha, 0, 1f);
- if(subAlpha > 0)
- {
- subAlpha -= Time.deltaTime * 4f;
- theColor = new Color(1, 1, 1, subAlpha);
- subtext.renderer.material.color = theColor;
- start.renderer.material.color = theColor;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement