how do i collide and kill the enemy while pressing space Unity 5 C#

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

private Rigidbody2D rbody;
private Animator anim;
public bool isAttacking = false;

// Use this for initialization
void Start () {
    rbody = GetComponent<Rigidbody2D>();
    anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update () {
    Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal") , Input.GetAxisRaw("Vertical"));

    //if not zero must be moving
    if (movement_vector != Vector2.zero)
    {
        anim.SetBool("isWalking", true);
        anim.SetFloat("input_x", movement_vector.x);
        anim.SetFloat("input_y", movement_vector.y);
    }
    else //sees if in idel or not changes anim
    {
        anim.SetBool("isWalking", false);

    }
    //movment by 1
    rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime);

    //sets attack to true if space hit
    if (Input.GetKeyDown(KeyCode.Space))
    {
        isAttacking = true;
       
    }
    //Makes anim attack
    if (isAttacking == true)
    {
        anim.SetBool("isAttacking", true);
        isAttacking = false;
       
    }
    else
    {
        anim.SetBool("isAttacking", false);
    }

}

//checks if touch enemy and then if can attack then kill
void OnTriggerEnter2D(Collider2D other)
{

    if (other.gameObject.CompareTag("Enemy"))
    {
        if (isAttacking==true)
        {
            Destroy(other.gameObject);
        }
    }
}

}//end

@username, in the OnTriggerEnter2D() function, instead of:

if(other.gameobject.CompareTag(“Enemy”)){
//Do stuff
}

Just use:

if(other.tag == “Enemy”){
//Do stuff
}

Ok, so to do that:

  1. Make a new float called:
    enemyDistance ----Code>>>> public float enemyDistance

  2. In Update(), put: enemyDistance=Vector3.Distance(enemy.transform.position,transform.position);

  3. In OnTriggerEnter2D(), type in (mostly add a little bit more info):

void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == “Enemy”)
{
if (isAttacking==true && enemyDistance <= 5) <<< If you want the distance to be closer or farther, then change the value 5.
{
Destroy(other.gameObject);
}
}
}