RPC affects all players?
Options
Hi, I wanted to add power ups to my game and I'm having some issues. For some reason, when walking through a powerup, the powerup's RPC gets applied to ALL players rather than the one who walked through it. Can I get a bit of help with this? Here's my code:
private void OnTriggerEnter2D(Collider2D collision) { if(collision.tag == "Player") { if(!isCollected) { photonView.RPC("Collect", PhotonTargets.All, collision.GetComponent<PhotonView>().ownerId); isCollected = true; } } } [PunRPC] public void Collect(int playerID) { PhotonView p = PhotonView.Find(playerID); anim.Play("Collect"); particles.Play(); if (Function == PowerUps.ScaleUp) { p.RPC("ScaleUp", PhotonTargets.All); } }
0
Answers
-
You don't have to send anything that identifies the RPCs "target". You are calling the RPC on a specific PhotonView (and all remove clients do the same).
The player who calls the RPC is sent automatically and accessible if you add a final paramter to a PunRPC being PhotonMessageInfo.
Also, you send the ownerId, which is not usable to find the view.
So this is buggy.0