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:
// 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?

Answers

  • r2qrq
    Options
    I forgot to mention this but i'm using Pun v2
  • r2qrq
    Options
    Bump
  • JPGOrdon
    Options
    @r2qrq Have you tried other methods of communication, such as events?
  • r2qrq
    Options
    I thought this was to proper way?
  • 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?
  • L3sc
    Options
    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.
  • r2qrq
    Options
    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.
  • r2qrq
    Options
    L3sc wrote: »
    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.