using UnityEngine;
using System.Collections;

[RequireComponent(typeof(ConstantForce2D))]
public class Magic : MonoBehaviour {

    public Vector2 SpawnPoint;
    public float duration = 3f;

    void Start()
    {
       StartCoroutine(timeToDestroy());
    }

    public Vector2 getSpawnPoint(Transform startTransform)
    {
        Vector2 InstansiatePos = new Vector2(startTransform.position.x + SpawnPoint.x, 
                                             startTransform.position.y + SpawnPoint.y);
        return InstansiatePos;  
    }

    IEnumerator timeToDestroy()
    {   
        yield return new WaitForSeconds(duration);
        Destroy(this.gameObject);   
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
            return;

        if (other.tag == "Enemy")
        {
            Destroy(other);
            Destroy(this.gameObject);   
        }                   
    }

}
