[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.



![[Unity] Removing grass grown on Terrain from scripts](https://kuroko-labo.com/wp/wp-content/uploads/2025/05/grass2.png)
![[Unity]I made a field with Gaia Pro 2023.](https://kuroko-labo.com/wp/wp-content/uploads/2025/01/image06.png)
![[Unity]I bought an OLD TV Filter.](https://kuroko-labo.com/wp/wp-content/uploads/2019/11/image05.png)
![[Unity]Try to create a circle gauge that advances when the mouse is clicked.](https://kuroko-labo.com/wp/wp-content/uploads/2019/07/circle.fw_.png)
![[Unity]Use localPosition to create a conveyor belt-like](https://kuroko-labo.com/wp/wp-content/uploads/2019/06/image01-1.png)
![[Unity]Obtain and display mouse coordinates](https://kuroko-labo.com/wp/wp-content/uploads/2019/03/image02.png)