- Home /
This question was
closed Oct 05, 2015 at 10:08 AM by
McPluffel for the following reason:
Found it out on my own
Question by
McPluffel · Sep 29, 2015 at 09:13 AM ·
networkingrespawning
Unity UNET Respawning Player with a new prefab
Some background on what I am trying to do: I am making a zombie mode for my game, where you are trying to hold off wave after wave with AI Zombies and player controlled zombies. If you die as a survivor, you are supposed to be respawned as a Zombie.
Here is my code:
[SerializeField] GameObject playerPrefab;
GameObject respawnButton;
void Start() {
if (isLocalPlayer) {
respawnButton = GameObject.Find("GameManager").GetComponent<GameManager_References>().respawnButton;
respawnButton.GetComponent<Button>().onClick.AddListener(Respawn);
}
}
[Client]
public void Respawn() {
if (isLocalPlayer) {
CmdRespawn();//this.gameObject.GetComponent<NetworkIdentity>().netId, this.playerControllerId);
}
}
[Command]
public void CmdRespawn() {//NetworkInstanceId playerNetId, short id) {
NetworkServer.Spawn(playerPrefab);
NetworkServer.ReplacePlayerForConnection(connectionToClient, playerPrefab, playerControllerId);
}
So, to the problem that I am encountering is that the respawn is triggered for EVERYONE, not only the client that called it. I have searched for this a long time now, and still no answers.
Thanks in advanced.
Comment