Network - SendMessageUpwards to Specific Client


For some reason, I can’t seem to send a ‘SendMessage’ to a specific client on my network. All I’m trying to do, is if a variable is true on my side (my network), then send a message to the client it relates to.

Let me be more detailed. I have a melee system, basically it shoots a raycast at the most closest/nearest client, if that client is within a certain distance, you can melee him. A melee just consists of a SendMessageUpwards(damage). Thats it! And for the life of me, I can’t get it working!

Now I’m messing around with RPCs and all sorts. Whats weird, is that my projectile gun uses a hit.SendMessageUpwards(damage), and it works just fine (might be because the projectiles are Network.Instantiate).

Anyway, here is my melee script (its an axe btw):

var damage : float = 40;
var swung : boolean = false;
var enemy : GameObject;

function Update () {
   enemy = FindClosestEnemy (); //uses Unity's FindGameObjectsWithTag example

   if(Input.GetButtonDown("Fire1") && swung == false){
      swung = true;

function doMelee(){
	var closest = enemy;
	var direction = enemy.transform.position - transform.position;
	var hit : RaycastHit;
	//var layerMask = 1 << 10;
	//fire raycast to determine distance
	if(Physics.Raycast (transform.position, direction, hit, Mathf.Infinity)){
		Debug.DrawLine (transform.position, hit.point,, 1);	
		if(hit.distance <= 2.0){
			//we are in melee distance
			print("** In melee distance! ** | Distance: " + hit.distance);
			//send damage message to client
			var viewID = Network.AllocateViewID();
			networkView.RPC("SendMeleeMessage", RPCMode.All, viewID);
	//play axe animation
	yield WaitForSeconds(1);
	swung = false;

What am I missing here?


I see the problem, the rpc is sent to your players GameObject, not the one that was hit.