mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
updated code snip
This commit is contained in:
parent
5dfc85931f
commit
4306e08eb5
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user