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,15 +38,17 @@ public class PlayerController : NetworkBehaviour
void Update() void Update()
{ {
if (currentTarget != null) if (isLocalPlayer)
if (currentTarget.tag == "Enemy") if (currentTarget != null)
if (Input.GetKeyDown(KeyCode.X)) if (currentTarget.tag == "Enemy")
CmdShoot(currentTarget); if (Input.GetKeyDown(KeyCode.X))
CmdShoot(currentTarget);
} }
[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;
} }
} }