Benchmark/Tanks example: name players for easier debugging

This commit is contained in:
mischa 2024-10-18 14:18:30 +02:00
parent fdc9369de4
commit f74d072165
2 changed files with 24 additions and 2 deletions

View File

@ -6,6 +6,17 @@ public class PlayerMovement : NetworkBehaviour
{ {
public float speed = 5; 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() void Update()
{ {
if (!isLocalPlayer) return; if (!isLocalPlayer) return;

View File

@ -22,14 +22,25 @@ public class Tank : NetworkBehaviour
[Header("Stats")] [Header("Stats")]
[SyncVar] public int health = 5; [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() void Update()
{ {
// always update health bar. // always update health bar.
// (SyncVar hook would only update on clients, not on server) // (SyncVar hook would only update on clients, not on server)
healthBar.text = new string('-', health); healthBar.text = new string('-', health);
// take input from focused window only // take input from focused window only
if(!Application.isFocused) return; if(!Application.isFocused) return;
// movement for local player // movement for local player
if (isLocalPlayer) if (isLocalPlayer)