Can't Send Function To Other Clients Using RPC
Options
Hello, I'm trying to send a function to all players once everyone in the room is dead my code is:
This is the function that should go off:
It goes off for the master client but doesn't activate for the other clients. Anyone know what I am doing wrong?
// Update is called once per frame [PunRPC] void Update () { if (PhotonNetwork.IsMasterClient == true) { if (PhotonNetwork.CurrentRoom.PlayerCount == playersdead) { PhotonView photonView = PhotonView.Get(this); this.photonView.RPC("RPC_EndGame", RpcTarget.All); Debug.Log ("The Game is Over"); } }
This is the function that should go off:
[PunRPC] public void RPC_EndGame () { isgameover = true; prespawn.canrespawn = false; GameOverUI.gameObject.SetActive(true); GameOverRUI.gameObject.SetActive(true); Invoke ("Returntolobby", 15.0f); }
It goes off for the master client but doesn't activate for the other clients. Anyone know what I am doing wrong?
0
Answers
-
I forgot to mention this but i'm using Pun v20
-
Bump0
-
I thought this was to proper way?0
-
Since RPC only communicate between the same PhotonView, first thought come to my mind is: Was the script attach to a scene object? or was this object network instantiated?
Also, was the playersdead sync correctly?
0 -
1)Why is your update function marked as [PunRPC]?
2)Sending rpc frequently like inside update may cause the client to crash.
3)Make sure the script containing the function must be in the same object with the photon view.0 -
ThomasKao_XRSpace wrote: »Since RPC only communicate between the same PhotonView, first thought come to my mind is: Was the script attach to a scene object? or was this object network instantiated?
Also, was the playersdead sync correctly?
It was attached to a scene object. It appears playersdead is synced because other clients can update the int and the host gets it.0 -
1)Why is your update function marked as [PunRPC]?
2)Sending rpc frequently like inside update may cause the client to crash.
3)Make sure the script containing the function must be in the same object with the photon view.
I thought I needed [PunRPC] when I was doing something with the network, I guess not. Okay, ill remove it and keep that in mind. I'll make sure to check later.0