[Unity] 在 Photon 的 PUN2 中任意时间执行方法。
PHOTON 是付费的,但我喜欢它,因为它是实现多人游戏的简单方法。
现在我们有了一个名为 fusion 的新计划,但我们还有一个仍在使用 pun2 的项目,我想编写一个脚本,在任意时间执行一个方法。
using UnityEngine;.
using Photon.Pun;.
public class PunTest : MonoBehaviourPunCallbacks.
{
void Start()
{
}
void Update()
{
photonView.RPC("RPCTest", RpcTarget.All, "Pero~"); }
}
[PunRPC]
void RPCTest(string str)
{
Debug.Log(str);
}
}
在实际项目中我不会这样写,但仅供参考: ……
在这段代码中,我们通过执行 photonView.RPC(“RPCTest”,RpcTarget.All, “Pero~”)来调用 RPCTest;每次进行更新时都会这样做。
指定了 RpcTarget.All,因此房间里的所有玩家都会运行 RPCTest 并记录调试 “peron”。
不,没有这样的实际案例,但我想过写一些实际的项目代码,但当我看到其中的内容时,我想,”哦,我不能展示它”,所以我写的代码非常随意。我很抱歉。



![[Unity] 从脚本中移除生长在地形上的草。](https://kuroko-labo.com/wp/wp-content/uploads/2025/05/grass2.png)
![[Unity]我用 Gaia Pro 2023 制作了一块田地。](https://kuroko-labo.com/wp/wp-content/uploads/2025/01/image06.png)
![[Unity]我买了一个旧电视滤波器。](https://kuroko-labo.com/wp/wp-content/uploads/2019/11/image05.png)
![[Unity]尝试创建一个圆规,当鼠标点击时,圆规会向前移动。](https://kuroko-labo.com/wp/wp-content/uploads/2019/07/circle.fw_.png)
![[Unity]使用 localPosition 创建类似传送带的系统。](https://kuroko-labo.com/wp/wp-content/uploads/2019/06/image01-1.png)
![[Unity]获取并显示鼠标坐标](https://kuroko-labo.com/wp/wp-content/uploads/2019/03/image02.png)