using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class confettiController : MonoBehaviour {
|
|
|
|
public float lifeTime = 0.5f;
|
|
public float speed = 5;
|
|
|
|
private float startTime;
|
|
private float startScale;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
float rand = Random.Range (0, 7);
|
|
int randColour = Mathf.FloorToInt (rand);
|
|
startTime = Time.time;
|
|
startScale = transform.localScale.x;
|
|
rigidbody2D.velocity = Random.onUnitSphere * speed;
|
|
|
|
switch (randColour) {
|
|
case 0:
|
|
renderer.material.color = Color.cyan;
|
|
break;
|
|
case 1:
|
|
renderer.material.color = Color.red;
|
|
break;
|
|
case 2:
|
|
renderer.material.color = Color.blue;
|
|
break;
|
|
case 3:
|
|
renderer.material.color = Color.green;
|
|
break;
|
|
case 4:
|
|
renderer.material.color = Color.yellow;
|
|
break;
|
|
case 5:
|
|
renderer.material.color = Color.magenta;
|
|
break;
|
|
default:
|
|
renderer.material.color = Color.black;
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
float newScale = Mathf.Lerp(0, startScale, Time.deltaTime / lifeTime);
|
|
transform.localScale = new Vector3(startScale-newScale, startScale-newScale, startScale-newScale);
|
|
|
|
if(Time.time - startTime > lifeTime) {
|
|
Destroy (gameObject, 0.0f);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//void OnCollisionEnter2D(Collision2D col){
|
|
// if (col.collider.tag == "ground" && Time.time - startTime > 2) {
|
|
// gameObject.GetComponent<BoxCollider2D> ().enabled = false;
|
|
// gameObject.GetComponent<Rigidbody2D> ().isKinematic = true;
|
|
// }
|
|
//}
|
|
|
|
|
|
}
|