using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Destructible2D
{
public class controller : MonoBehaviour {
	private float movementSpeed = 5f;
	public GameObject ExplosionPrefab;
	public int FractureCount = 1;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		//GetComponent<Rigidbody2D>().MovePosition(GetComponent<Rigidbody2D>().position+Vector2.forward * movementSpeed * Time.deltaTime);
		//GetComponent<Rigidbody2D>().AddForce(transform.up*movementSpeed*Time.deltaTime);
		

	}

	void OnCollisionEnter2D(Collision2D coll)
	{
			//if (coll.gameObject.tag == "Planet" || coll.gameObject.tag == "Turret" || coll.gameObject.tag == "Asteroid" || coll.gameObject.tag == "Bullet") {
			
			//Debug.Log (coll.gameObject.name);
					var screenPoint = GetComponent<Transform> ().position;
				var screenRotation = GetComponent<Transform> ().rotation;
					//var worldPoint    = Camera.main.ScreenToWorldPoint(screenPoint);
					//var collider      = Physics2D.OverlapPoint(worldPoint);

					
					
					
						var destructible = coll.gameObject.GetComponent<D2dDestructible>();

						
							Destroy (this.gameObject);
							if (ExplosionPrefab != null)
							{
								//var worldRotation = Quaternion.Euler(0.0f, 0.0f, Random.Range(0.0f, 360.0f)); // Random rotation around Z axis

							Instantiate(ExplosionPrefab, screenPoint, screenRotation);
							}
	
			//}
	}


}
}
