I do understand that questions like this have been asked before, but I’ve looked at many of them with no fix to my issue. I have a raycast that is calling a function through SendMessage and apply damage to an enemy.
The first code is
function AttackDamage ()
{
//Attack function
var hit : RaycastHit;
if (Physics.Raycast(TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
Debug.Log("Damage");
}
}
}
and the code with the function I want to call is
var Health = 100;
function Update ()
{
if(Health <= 0)
{
Dead();
}
}
function ApplyDamage(Damage : int)
{
Debug.Log("Damaged");
Health -= Damage;
}
function Dead()
{
Destroy(gameObject);
}
The AttackDamage function does call the debug at the end so I imagine that there is not issue with that function, I think it is just SendMessage not calling the ApplyDamage function. I have also tried BroadcastMessage and that hasn’t worked either.
Ask if you need anything else from me, thanks!