[Unity] Executing a method at an arbitrary time with Photon’s PUN2


I like PHOTON because it’s paid for, but it’s easy to implement multiplayer.

We have a new plan called fusion now, but we also have a project that still uses pun2 and would like to write a script to execute a method at any given time.

.
using UnityEngine; using Photon.
Pun; using Photon.

public class PunTest : MonoBehaviourPunCallbacks
{
    void Start()
    {

    }

    void Update()
    {
        photonView.RPC("RPCTest", RpcTarget.All, "Pero~"); }
    }

    [PunRPC]
    void RPCTest(string str)
    {
        Debug.Log(str); }
    }
}

.
I wouldn’t write it this way in an actual project, but it’s just for reference: ……

This code calls RPCTest by executing photonView.RPC(“RPCTest”, RpcTarget.All, “Pero~”); each time an Update is made.

RpcTarget.All is specified, so all players in the room will run RPCTest and log a debugging “peron”.

No, there is no actual case like this, but I was going to write a part of the actual project code, but when I saw the contents, I thought, “Oh, I can’t show it,” so I wrote a very appropriate code. Sorry.