Hi guys. So I am trying to create a melee system for my game. Just when I thought I had a grasp of RPCs I can’t get this code to work…
This is the function in my creature script… (Creature you play as)
@RPC
function MeleeAttack(viewID : NetworkViewID, DamageMelee : int){
var HitAttack : RaycastHit;
var Direction : Vector3 = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, Direction * Range, Color.red);
if (Physics.Raycast(transform.position, Direction, HitAttack, Range)){
if (HitAttack.collider.gameObject.CompareTag("Player")){
HitAttack.collider.SendMessageUpwards("MeleeAttacked", DamageMelee);
}
}
}
This is the script for the human taking damage…
function MeleeAttacked(DamageMelee : int)
{
sanity -= DamageMelee;
}
What am I missing? Any help would be really appreciated!