Hello unity Community !! I am new to the unity software coming from gamemaker and I am wondering if I am doing this script correctly? I am following this tutorial
but every time I hit the capsule the Health doesn’t drop and the capsule doesn’t die either
Also there are no errors.
Enemy Logic
#pragma strict
var Health = 100;
function Update ()
{
if(Health <=0)
{
Dead();
}
}
function ApplyDamage(TheDamage : int)
{
Health -=TheDamage;
}
function Dead()
{
Destroy (gameObject);
}
Melee System
#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);
}
}
}
}