using UnityEngine;
using System.Collections;

public class JuiceLifeCycle : MonoBehaviour {

	public float LifeSpan;
	public float MoveTime;
	public Vector2 MoveVector;
	public Vector2 Splatter;

	private float startTime;
	private GameController gc;

	// Use this for initialization
	void Start () {
		GameObject cgo = GameObject.Find ("GameController");
		gc = cgo.GetComponent<GameController>();

		startTime = Time.time;
		Vector2 splatVec = new Vector2((float)(gc.rand.NextDouble()*Splatter.x + 0.5f*Splatter.x), (float)(gc.rand.NextDouble()*Splatter.y + 0.5f*Splatter.y));
		MoveVector += splatVec;
	}
	
	// Update is called once per frame
	void FixedUpdate () {
		if(Time.time - startTime > LifeSpan)
		{
			GameObject.Destroy(gameObject);
			return;
		}

		if(Time.time - startTime < MoveTime)
		{
			transform.position = transform.position + (Vector3)MoveVector*Time.fixedDeltaTime;
		}
	}
}
