Enemy health not decreasing

Okay so I have a melee system and a enemy health system, they both work and let me play in game, however the enemy’s health just does not decrease for some reason?

Here are both scripts

ENEMY HEALTH

#pragma strict
var Health = 100;

function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
}

MELEE SYSTEM

 #pragma strict
var TheDammage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
function Update()
{
if (Input.GetButtonDown ("Fire1"))
{
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}

Ok, so the problem is either the distance check(set the MaxDistance to 5 for a last test) which seems unlikly, or it is the send message. Change the send massage line to this :

hit.collider.gameObject.SendMessage("ApplyDamage");

And change this script to this :

#pragma strict

var Health : int = 100;

function ApplyDamage() {

    Health = Health - 50;
    
    if (Health <= 0) {
    
        Debug.Log("I have sustained a lethal injury...");
        Health = 0;
    }
}

Making sure this script is on the collider object of the target, if the collider is on a child and this script is on the parent then you will have to script up through the objects hierarchy to find the the object that has this script attached(in your other script).

lol, I’ve just spotted the probable cause and corrected it, Damage was written as Dammage in your ApplyDamage function, fixed this typo, now give it a go :slight_smile: