UNet Stunning an enemy player
So I'm pretty new to unity and multiplayer and I've been trying to make a simple magic FPS where when one player shoots the other one it freezes the other player for a few seconds and then unfreezes them. I've tried a few different variations of this:
[Command]
void CmdTellServerWhoWasShot(string uniqueID, int dmg){
GameObject go = GameObject.Find (uniqueID);
go.GetComponent<Player_Health>().DeductHealth(dmg);
go.GetComponent<Player_Shoot>().BarragePlayer();
}
public void BarragePlayer(){
GameObject go = (GameObject)Instantiate(BarrageModel, transform.position + new Vector3(0, 1.5f, 0), transform.rotation);
NetworkServer.Spawn(go);
StartCoroutine(Stun(go));
}
public IEnumerator Stun(GameObject barrageModel) {
if(isBarraged){
Debug.Log("Player is already barraged.");
} else {
isBarraged = true;
Debug.Log("barrage is now true");
//GameObject go = (GameObject)Instantiate(BarrageModel, transform.position + new Vector3(0, 1.5f, 0), transform.rotation);
GetComponent<CharacterController>().enabled = false;
GetComponent<Player_Shoot>().enabled = false;
yield return new WaitForSeconds(3);
GetComponent<CharacterController>().enabled = true;
GetComponent<Player_Shoot>().enabled = true;
isBarraged = false;
Debug.Log("barrage is now false");
NetworkServer.Destroy(barrageModel);
}
}
It works when the client shoots the server/host but when the server shoots the client the barrage appears and destroys itself as it should but the player is never "stunned." I'm guessing this is because the character controller/player_shoot scripts are only enabled for the clients so I cant really access them from the server.
How can I send a message from the server to the client to tell them to deactivate their scripts temporarily? Is there something I'm missing? The documentation on this stuff seems pretty sparse atm
Your answer
Follow this Question
Related Questions
UNET with Secure Firewalls 0 Answers
Bullets showing only on host and weapons not appearing 3 Answers
Instantiated Players Transform Not Changing 0 Answers