Hello,
I’m working on a simple melee system, basically I have an axe, that every time you click, an animation plays of your character swinging the axe. Also on the script, I have a raycast system, that detects the distance of the player and the enemy. If the distance is close enough, then allow the ‘melee click’ to do damage (SendMessage).
But it doesn’t seem to be working. I think I’ve narrowed it down to my SendMessage event, not sure if thats getting across for some reason, anyway, have a look and let me know what you think. (Right now, there is no ‘click’ as soon as the player gets close to the enemy, it will trigger the damage):
function Update () {
enemy = GameObject.Find("/Player(Clone)Remote");
var closest = enemy;
var direction = enemy.transform.position - transform.position;
var hit : RaycastHit;
var layerMask = 1 << 10;
if(Physics.Raycast (transform.position, direction, hit, Mathf.Infinity, layerMask)){
Debug.DrawLine (transform.position, hit.point, Color.blue, 1);
if(hit.distance <= 2.0){
//we are in melee distance
print("** In melee distance! ** | Distance: " + hit.distance);
//hit.collider.gameObject.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
//enemy.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
//if(GameObject.FindWithTag("Player")){
hit.collider.transform.root.SendMessageUpwards("ApplyDamage", 110, SendMessageOptions.DontRequireReceiver);
//}
}
}
}