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

public class DeleteController : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.Delete))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

            if (hit != null && hit.collider != null)
            {
                GameObject obj = hit.collider.gameObject;
                if (obj.GetComponent<DeletableElement>() != null)
                {
                    Destroy(hit.collider.gameObject);
                }

                if (obj.GetComponentInParent<DeletableElement>() != null)
                {
                    Destroy(hit.collider.gameObject.transform.parent.gameObject);
                }
            }
        }
	}
}
