From 4306e08eb534800758ca912be806373354b55243 Mon Sep 17 00:00:00 2001 From: Chris Langsenkamp Date: Wed, 2 Oct 2019 13:48:58 -0400 Subject: [PATCH] updated code snip --- doc/Guides/Sync/SyncVars.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/Guides/Sync/SyncVars.md b/doc/Guides/Sync/SyncVars.md index fb37d7d5a..6c9f34ff2 100644 --- a/doc/Guides/Sync/SyncVars.md +++ b/doc/Guides/Sync/SyncVars.md @@ -22,7 +22,7 @@ public class Enemy : NetworkBehaviour void OnMouseUp() { - NetworkIdentity ni = NetworkClient.connection.playerController; + NetworkIdentity ni = NetworkClient.connection.identity; PlayerController pc = ni.GetComponent(); pc.currentTarget = gameObject; } @@ -38,15 +38,17 @@ public class PlayerController : NetworkBehaviour void Update() { - if (currentTarget != null) - if (currentTarget.tag == "Enemy") - if (Input.GetKeyDown(KeyCode.X)) - CmdShoot(currentTarget); + if (isLocalPlayer) + if (currentTarget != null) + if (currentTarget.tag == "Enemy") + if (Input.GetKeyDown(KeyCode.X)) + CmdShoot(currentTarget); } [Command] public void CmdShoot(GameObject enemy) { + // Do your own shot validation here because this runs on the server enemy.GetComponent().health -= 5; } }