- Home /
RPC failed to send
Hello, I'm trying to make an RPC command to take away health. here is the code
if (Physics.Raycast(transform.position, transform.forward, hit)){
if (hit.transform.tag == "players"){ //
if(GetComponent(NetworkView).networkView.isMine){
var hitID : NetworkView = hit.transform.GetComponent(NetworkView);
Debug.Log("You hit a player id:" + hitID.viewID);
hitID.RPC("ChangeHp", RPCMode.All,hitID.viewID,10);
}
}
}
}
@RPC function ChangeHp(targetID : NetworkViewID , AmountDamage : float) { currentHealth -= AmountDamage;
}
and here is the error that I'm getting "Sending RPC failed because 'ChangeHp' parameter 0 didn't match the RPC declaration. Expected 'System.Int32' but got 'UnityEngine.NetworkViewID' UnityEngine.NetworkView:RPC(String, RPCMode, Object[]) raycasting:Shoot() (at Assets/raycasting.js:43)" it is giving me this error right here - hitID.RPC("ChangeHp", RPCMode.All,hitID.viewID,10);
What am I doing wrong?
Answer by Owen-Reynolds · Jan 22, 2012 at 05:59 PM
It's telling you that changeHP looks something like: ChangeHP(int target, int hpChange)
It expects an int as the first input (which is the 3rd value of the RPC.) Technically, hitID.viewID isn't an int.
We know(?) that IDs are stored as ints. So, (int)hitID.viewID
should fix it (untested.)
But, it looks like that's an extra parm. Just: hitID.RPC("ChangeHp", RPCMode.All,10);
should be run just fine by the hitID object on each client.
Your answer
Follow this Question
Related Questions
A couple of questions about Networking. 0 Answers
Sending an RPC 1 Answer
Network Chat not sending messages to other clients 1 Answer