I want to attack me enemy and decrease their health, but t won't work, what am I doing wrong with my script?

For some time, I have been looking up tutorials to write a script in which my player can use a weapon and that weapon will damage the enemy and take away their health. Now, I have a script that the enemy damages the layer and takes away their health tat works, so I took it and tried to reverse the parts but it still does not work. What do I need to make it work?

The Script Below:

var Damage : int = 50;
var Animation;

private var enemy : GameObject;
private var enemyHealth : EnemyHealth;
private var enemyInRange : boolean;

function Awake () 
{
    Animation = GetComponent.<Animation>();
    
    enemy = GameObject.FindGameObjectWithTag ("Enemy");
    enemyHealth = enemy.GetComponent (EnemyHealth);
}

function Update () 
{
    if(Input.GetButtonDown("Fire1"))
    {
        GetComponent.<Animation>().Play("Pick");
    }
}

function OnTriggerEnter (other : Collider)
    {
      if(other.gameObject == enemy)
        {
          enemyInRange = true;
          Debug.Log("Enemy Hit");
        }
    }

function OnTriggerExit (other : Collider)
    {
      if(other.gameObject == enemy)
        {
          enemyInRange = false;
        }
    }

function Attack ()
   {
     if(enemyHealth.Health > 0)
       {
         enemyHealth.ApplyDamage (Damage);
       }
   }

and the script for my enemy health:

var Health = 100;

function Update () 
{
    if(Health <= 0)
    {
        Dead();
    }
}

function ApplyDamage(TheDamage : int)
    {
        Debug.Log("Damaged");
        Health -= TheDamage;
    }

    function Dead() 
    {
        Destroy(gameObject);
    }

You need to call Damage function. your attack which is supposed to call damage is never called.

function OnTriggerEnter (other : Collider)
     {
       if(other.gameObject == enemy)
         {
           enemyInRange = true;
           Debug.Log("Enemy Hit");
Attack();
         }
     }

---------THE ATTACK FUNCTION--------------

 function Attack () { 
    Debug.Log("BEING ATTACKED");
     if(enemyHealth.Health > 0) { 
    enemyHealth.ApplyDamage (Damage); 
    } 
    }

Okay I wrote up a quick script, attach the ColliderCombat to the weapon, and the EntityScript to the player and the enemies, and just set the EntityType, I also made it so if you want NPC’s seperately, the wont be involved in the combat.
Also added an HP handler. I have not tested it though.
EDIT: The purpose of the “entityCollider” is incase you have other colliders on your player object, it ensures that only the weapon collider and the entity collider can provide the event.
Collider Script is:

using UnityEngine;
using System.Collections;

public class ColliderCombat : MonoBehaviour
{
    #region Data
    public int minDamage;
    public int maxDamage;
    #endregion
    void OnCollisionEnter(Collision collision)
    {
        EntityScript defender = collision.collider.gameObject.GetComponent<EntityScript>();
        if (gameObject.GetComponent<EntityScript>().entityType == EntityScript.EntityType.Enemy && 
            defender.entityType == EntityScript.EntityType.Player)
        {
            if (collision.collider == defender.entityCollider)
            {
                defender.HitPoints -= Random.Range(minDamage, maxDamage);
            }
        }
        else if (gameObject.GetComponent<EntityScript>().entityType == EntityScript.EntityType.Player &&
            defender.entityType == EntityScript.EntityType.Enemy)
        {
            if (collision.collider == defender.entityCollider)
            {
                defender.HitPoints -= Random.Range(minDamage, maxDamage);
            }
        }
    }

Entity Script:

using UnityEngine;
using System.Collections;

public class EntityScript : MonoBehaviour
{
    #region Data
    public Collider entityCollider;
    public int maxHitPoints = 100;
    private int hitPoints = 100;
    public int hpRegen = 1;
    public int regenInterval = 60;
    private int regenSwitch = 0;
    public int HitPoints { get { return hitPoints; } set
        {
            hitPoints = value;
            if (hitPoints <= 0) { deathEvent(); }
        } }
    public enum EntityType { Player, Enemy, NPC }
    public EntityType entityType;
    #endregion
    void Update()
    {
        regenSwitch++;
        if (regenSwitch > 60)
        {
            regenSwitch = 0;
            if (HitPoints < maxHitPoints - hpRegen)
            {
                HitPoints += hpRegen;
            }
            else
            {
                HitPoints = maxHitPoints;
            }
        }
    }

    private void deathEvent()
    {
        //Death stuff here
    }
}

Maybe this Will help

Enemyscript enemy;



Void OnTriggerEnter(Collider other){
If(other.CompareTag("enemy")){

enemy = Other.GetComponent<the enemy script>.();
enemy.Damage(int);

}

}

@Draggonnoble

Health C#

`using UnityEngine;

public class Health : MonoBehaviour
{
public const int maxHealth = 100;
%|-1847962930_2|%

public void TakeDamage(int amount)
%|493011656_3|%
currentHealth -= amount;
%|2022189198_5|%
%|-731059696_6|%
%|-183514112_7|%
Debug.Log(“Dead!”);
}
%|916447909_10|%
}
`

Bullet C#

`using UnityEngine;
using System.Collections;

public class Bullet : MonoBehaviour {
%|420083905_11|%
%|1400404717_12|%
%|-2020662319_13|%
%|464509255_14|%
%|-330945156_15|%
if (health != null)
%|-222940933_17|%
health.TakeDamage(10);
%|-1844065826_19|%

%|59224891_20|%
}
}`