首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Unity Photon multiplayer中更改其他客户端变量?

如何在Unity Photon multiplayer中更改其他客户端变量?
EN

Stack Overflow用户
提问于 2016-09-27 21:34:45
回答 2查看 3.5K关注 0票数 0

我对PunRpc调用有点困惑,我试过PhotonTarget.Others,看看它是否能在其他客户端运行--;,但不起作用。

目前,我想知道当我按下空格键时,如何在其他客户机上运行。

这就是我尝试过的:这是命令:

photonView.RPC("healthReduction", PhotonTargets.Others, null);

这是RPC

    [PunRPC]
void healthReduction()
{
    health--;
    Debug.Log("Health--");
}

但是它仍然不能工作。

EN

回答 2

Stack Overflow用户

发布于 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;

票数 0
EN

Stack Overflow用户

发布于 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--;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39726111

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档