using UnityEngine;
using System.Collections;

public class Projectile : MonoBehaviour 
{
	public GameObject explosion;

	[SerializeField]
	float MAX_SPEED = 1.0f;
	
	Vector2 direction;
	
	public void Start ()
	{
		StartCoroutine (Destroy ());
	}
	
	void Update () 
	{
		transform.position += transform.TransformDirection (transform.up);
	}

	void OnCollisionEnter2D(Collision2D c)
	{
		if(c.gameObject.tag == "enemy")
		{
			if (explosion != null)
			{
				Instantiate(explosion, c.transform.position, Quaternion.identity);
			}
			
			Destroy(c.gameObject);

			ScoreSystem.Score();
		}
	}

	private IEnumerator Destroy () 
	{
		yield return new WaitForSeconds(3.0f);
		Destroy (gameObject);
	}
	//Destroy when exit screen. Or After 3 seconds
}
