Following this Guide: 3. Unity Tutorial Animation and Health - Create a Survival Game - YouTube
Everything seems correct, but the enemy (capsule) simply doesn’t lose health nor die. I’ve been at it for an hour or two and tried all I could, but nothing seems to be in my favor.
the two scripts are:
=====================================================
MeleeSystem Below
#pragma strict
var TheDamage : 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", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
=================================================================================
EnemyLogic:
#pragma strict
var Health = 100;
function ApplyDamage (TheDamage : int)
{
Health -= TheDamage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
Destroy (gameObject);
}
EDIT:
I made some tweaks the code(s) will be listed for paste bin (it takes up spaces) below.
I think I have fixed some stuff, but now I have only one ERROR, it reads as follows.
Assets/EnemyLogic.js(7,12): BCE0034: Expressions in statements must only be executed for their side-effects.