[RPC] Execute function on other?

Options
Hi,

Player does raycast test when shooting.
If hits, it calls for a function on other players.
In order to call this function only with the correct player, I check if the scripts belongs to the correct player.

[code2=csharp]void RaycastHitting(RaycastHit hit) {
photonView.RPC("ExplodeBullet", PhotonTargets.Others, PhotonView.Get(hit.transform.gameObject).owner, hit.point);
}

[RPC]
void ExplodeBullet(PhotonPlayer runOnPlayer, Vector3 pos) {
print(runOnPlayer + " " + photonView.owner);
if (photonView.owner == runOnPlayer) {
...
}
}[/code2]

The funny thing is that the console prints value of runOnPlayer fine, but photonView.owner as the shooter player, though it's a Local variable...?

What am I doing wrong?

Btw, if I'm just making a fool out of myself and there's actually an simple way to call a function on other players, please let me know.

Thanks.

Comments

  • Solved.
  • Could you maybe write down how you solved it?
    Just in case someone else get's the same problem.
  • ahillel wrote:
    photonView.RPC("ExplodeBullet", PhotonTargets.Others, PhotonView.Get(hit.transform.gameObject).owner, hit.point);
    Instead shouldn't you do

    photonView.RPC("ExplodeBullet", PhotonView.Get(hit.transform.gameObject).owner, hit.point);

    Not use OTHERS, as you're filtering out on an owner, just send it to that one owner.

    At least this is how it works in legacy Unity3D networking.
  • Tobias
    Options
    If you send the RPC only to the owner, only that client will notice the ExplodeBullet. Nobody else will even notice until the owner then again updates everyone.
    That might be ok (depending on the game) but it's more likely that the RPC should have a visible effect for everyone. It's only executed on the GameObject that the PhotonView is attached to, anyways.