【问题标题】:Unity3d unet - TargetRPC call originating from ClientUnity3d unet - 来自客户端的 TargetRPC 调用
【发布时间】:2017-05-15 07:39:02
【问题描述】:

众所周知,缺少 Unet 的文档。

我很想得到这个答案,希望它可以帮助其他人稍后搜索。

这是我想要做的:

  1. 在播放器客户端上使用射线投射检测命中。
  2. 使用 [Command] 向专用服务器指示命中
  3. 通知使用 [TargetRPC] 命中的一个客户端

问题是 TargetRPC 需要一个 NetworkConnection 值,但唯一记录在案的方法是使用该对象中的 ConnectToClient - 我没有,我需要获取。

如何以可以转换为正确 NetworkConnection 值的方式识别我在客户端点击到服务器的播放器。

在本地玩家权限对象上:

CmdIHitSomeone(unknown);

[Command]
void CmdIHitSomeone(NetworkConnect unknown) {
  TargetLetYourVictimFeelIt(unknown);
}

[TargetRPC]
void TargetLetYourVictimFeelIt(NetworkConnection unknown){
  //do something bad here
}

【问题讨论】:

    标签: c# multiplayer unet


    【解决方案1】:
    [Command]
    void CmdIHitSomeone(int amountToHit, NetworkIdentity target) 
    {
      TargetLetYourVictimFeelIt(target.connectionToClient , amountToHit);     
    }
    [TargetRPC]
    void TargetLetYourVictimFeelIt(NetworkConnection target, int amount)
    {
      //do something bad here
    }
    // call your command by getting NetworkIdentitiy component of your target/enemy
    GameObject target; 
    CmdIHitSomeone(10, target.GetComponent<NetworkIdentity>());
    

    【讨论】:

      【解决方案2】:
      NetworkConnection connnection = NetworkServer.objects[netId].connectionToClient;
      

      【讨论】:

      • 能否请您扩展您的答案?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2013-05-16
      • 1970-01-01
      相关资源
      最近更新 更多