updated code snip

This commit is contained in:
Chris Langsenkamp 2019-10-02 13:48:58 -04:00
parent 5dfc85931f
commit 4306e08eb5

View File

@ -22,7 +22,7 @@ public class Enemy : NetworkBehaviour
void OnMouseUp() void OnMouseUp()
{ {
NetworkIdentity ni = NetworkClient.connection.playerController; NetworkIdentity ni = NetworkClient.connection.identity;
PlayerController pc = ni.GetComponent<PlayerController>(); PlayerController pc = ni.GetComponent<PlayerController>();
pc.currentTarget = gameObject; pc.currentTarget = gameObject;
} }
@ -38,6 +38,7 @@ public class PlayerController : NetworkBehaviour
void Update() void Update()
{ {
if (isLocalPlayer)
if (currentTarget != null) if (currentTarget != null)
if (currentTarget.tag == "Enemy") if (currentTarget.tag == "Enemy")
if (Input.GetKeyDown(KeyCode.X)) if (Input.GetKeyDown(KeyCode.X))
@ -47,6 +48,7 @@ public class PlayerController : NetworkBehaviour
[Command] [Command]
public void CmdShoot(GameObject enemy) public void CmdShoot(GameObject enemy)
{ {
// Do your own shot validation here because this runs on the server
enemy.GetComponent<Enemy>().health -= 5; enemy.GetComponent<Enemy>().health -= 5;
} }
} }