RPC Raycast - Please Halp

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!

Hi MILTON!, first of all, I can’t find the Range variable in your script, but maybe you created it in another place.
Second of all, when making a video game and when something is wrong, use the Log.
Because maybe the MeleeAttacked, is never called. And I already did a melee attack in one of my projects, and maybe you should do the raycast in local, (btw make a Debug.Log to see if the raycast hit something), and if it hit something, send a RPC to the hited player to remove him sanity.

So you have to add the RPC tag in front of the MeleeAttacked function.

And remember, use Log to see if method aren’t called or if they aren’t doing what you want them to do.

V