I made two scripts, one is called MeleeSystem which is responsible for getting the distance between me and an enemy object/player and based on that, apply 20 damage to that object’s health, which is found in my EnemyHealth class.
here’s my code
MeleeSystem Class
#pragma strict
var Damage : int = 20;
var Distance : float;
var MaxDistance : float = 1.5f;
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)
{
transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
EnemyHealth Class
#pragma strict
var Health = 100;
function ApplyDamage(Damage : int)
{
Health -= Damage;
print(Health);
}
function Update()
{
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
Destroy(gameObject);
}
I am getting this warning: The referenced script on this behaviour is missing!
that’s for both the classes. And yes, the classes are correctly placed.