From f74d0721650b052f918f08695a2485e139a566f1 Mon Sep 17 00:00:00 2001 From: mischa Date: Fri, 18 Oct 2024 14:18:30 +0200 Subject: [PATCH] Benchmark/Tanks example: name players for easier debugging --- .../Examples/Benchmark/Scripts/PlayerMovement.cs | 11 +++++++++++ Assets/Mirror/Examples/Tanks/Scripts/Tank.cs | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Examples/Benchmark/Scripts/PlayerMovement.cs b/Assets/Mirror/Examples/Benchmark/Scripts/PlayerMovement.cs index 68651232b..c400113d5 100644 --- a/Assets/Mirror/Examples/Benchmark/Scripts/PlayerMovement.cs +++ b/Assets/Mirror/Examples/Benchmark/Scripts/PlayerMovement.cs @@ -6,6 +6,17 @@ public class PlayerMovement : NetworkBehaviour { public float speed = 5; + // naming for easier debugging + public override void OnStartClient() + { + name = $"Player[{netId}|{(isLocalPlayer ? "local" : "remote")}]"; + } + + public override void OnStartServer() + { + name = $"Player[{netId}|server]"; + } + void Update() { if (!isLocalPlayer) return; diff --git a/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs index 28550bfcb..cf99f8527 100644 --- a/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs +++ b/Assets/Mirror/Examples/Tanks/Scripts/Tank.cs @@ -22,14 +22,25 @@ public class Tank : NetworkBehaviour [Header("Stats")] [SyncVar] public int health = 5; + // naming for easier debugging + public override void OnStartClient() + { + name = $"Player[{netId}|{(isLocalPlayer ? "local" : "remote")}]"; + } + + public override void OnStartServer() + { + name = $"Player[{netId}|server]"; + } + void Update() { // always update health bar. // (SyncVar hook would only update on clients, not on server) healthBar.text = new string('-', health); - + // take input from focused window only - if(!Application.isFocused) return; + if(!Application.isFocused) return; // movement for local player if (isLocalPlayer)