using UnityEngine;

[AddComponentMenu("Destructible 2D/D2D Replace On Collision")]
public class D2D_ReplaceOnCollision_obi : MonoBehaviour
{
	public float RelativeVelocityRequired;
	
	public GameObject Spawn;

    // Use this for initialization
    void Start()
    {

    }

    protected virtual void OnCollisionEnter2D(Collision2D collision)
	{
		Destroy(gameObject);
		
		if (Spawn != null)
		{
			if (collision.relativeVelocity.magnitude >= RelativeVelocityRequired)
			{
				var contact0 = collision.contacts[0];
				
				Instantiate(Spawn, contact0.point, transform.rotation);
			}
		}
	}
}