Unity3d PhotonTargets.AllBuffered在主客户端上无法正常工作

时间:2019-06-05 11:23:36

标签: unity3d rpc multiplayer photon

我正在制作团队死亡竞赛游戏,当有人死亡时,死家伙调用rpc方法,该方法通过PhotonTargets.AllBuffered在我的游戏管理器脚本中为团队增加得分。

我遇到了这个问题:

普通客户互相残杀,团队得分为2-2,但是当主要客户杀死某人时,分数必须为3-2,这仅适用于当时玩的人。但是如果有人后来加入游戏,他们仍然会看到得分是2-2。因此,它不适用于仅由主客户添加的分数。

这是玩家健康脚本

[PunRPC]
 public void TestDmg(int damage,string shootername)
 {
     health -= damage;

     if (health <= 0)
     {
         if (photonView.isMine)
         {                         
             if (GetComponent<TeamBase>().myTeam == TeamBase.Team.team1)
             {
                 gameManager.photonView.RPC("AddScoreToTeam2", PhotonTargets.AllBuffered,10);
             }
             else if (GetComponent<TeamBase>().myTeam == TeamBase.Team.team2)
             {
                 gameManager.photonView.RPC("AddScoreToTeam1", PhotonTargets.AllBuffered, 10);
             }

         }

         health = 100;
     }

 }

这是游戏管理器脚本

[PunRPC]
 public void AddScoreToTeam1(int score)
 {       
    team1Score += score;
 }

 [PunRPC]
 public void AddScoreToTeam2(int score)
 {   
     team2Score  += score;   
 }

0 个答案:

没有答案