From 1f61f9544a04d7c887835ab249d1472c4d186a79 Mon Sep 17 00:00:00 2001 From: mischa Date: Mon, 31 Jul 2023 16:21:55 +0800 Subject: [PATCH] can't reproduce --- Assets/Mirror/Examples/Tanks/Scripts/Tank.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs index fe1d8af7a..fa7ad2132 100644 --- a/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs +++ b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs @@ -60,16 +60,25 @@ void CmdFire() { GameObject projectile = Instantiate(projectilePrefab, projectileMount.position, projectileMount.rotation); NetworkServer.Spawn(projectile); - RpcOnFire(); + // RpcOnFire(connectionToClient); + TargetDoMagic(connectionToClient, 42); } // this is called on the tank that fired for all observers - [ClientRpc] - void RpcOnFire() + [TargetRpc] + void RpcOnFire(NetworkConnectionToClient conn) { + Debug.Log($"RpcOnFire with conn={conn}"); animator.SetTrigger("Shoot"); } + [TargetRpc] + public void TargetDoMagic(NetworkConnectionToClient target, int damage) + { + // This will appear on the opponent's client, not the attacking player's + Debug.Log($"Magic Damage = {damage}"); + } + [ServerCallback] void OnTriggerEnter(Collider other) {