我对PunRpc调用有点困惑,我试过PhotonTarget.Others,看看它是否能在其他客户端运行--;,但不起作用。
目前,我想知道当我按下空格键时,如何在其他客户机上运行。
这就是我尝试过的:这是命令:
photonView.RPC("healthReduction", PhotonTargets.Others, null);
这是RPC
[PunRPC]
void healthReduction()
{
health--;
Debug.Log("Health--");
}
但是它仍然不能工作。
发布于 2016-10-05 22:10:04
我通过使用一个实例和两个不同的命名脚本解决了这个问题,例如,如果我想从PlayerManager访问PlayerManager1脚本,我就执行这个PlayerManager1.Instance.photonView.RPC("reduceMyHealth",PhotonTargets.All,null)
这将在PlayerManager1中调用reduceMyHealth() PunRpc。
为此,您必须将以下代码添加到要访问的脚本中:static public PlayerManager1 Instance;
和start(){}Instance = this;
发布于 2018-12-13 22:29:29
我认为这很容易解决。源代码如下所示。
public class TestPhoton : Photon.PunBehaviour
{
public PhotonView gameView;
void Start()
{
gameView = this.GetComponent<PhotonView>();
}
public void OnClickTest()
{
photonView.RPC("HealthReduction", PhotonTargets.Others);
}
[PunRPC]
public void HealthReduction()
{
health--;
}
}
https://stackoverflow.com/questions/39726111
复制相似问题