public void kill(Player player) { if (player.isRespawned) { currentSceneState.players.Remove(player); Debug.Log("Player copy is dead"); return; } History.PlayerHistory.PlayerHistoryElement rollBackPlayer = currentPlayerHistory.getPlayback(); if (rollBackPlayer == null) { Debug.Log("You lose"); showDefeat(); return; } if (resurectedTimes == maxResurects) { showDefeat(); return; } // Ghost var ghost = Instantiate(player); rollBackPlayer.position.y = 1.5f; ghost.transform.position = rollBackPlayer.position; ghost.currentHealth = rollBackPlayer.health; Debug.Log("Respawn with " + rollBackPlayer.health); ghost.respawnWith(currentPlayerHistory); ghost.setLightColor(ghostColor); ghost.setBorders(limitTopLeft, limitBotRight); currentSceneState.players.Add(ghost); // Playable player char var respawned = Instantiate(player); rollBackPlayer.position.y = 3.0f; respawned.transform.position = rollBackPlayer.position; respawned.currentHealth = rollBackPlayer.health; respawned.setBorders(limitTopLeft, limitBotRight); playerHealthBar.changeSubscription(respawned); currentSceneState.players.Add(respawned); resurectedTimes++; resurectsLeft.text = "" + (maxResurects - resurectedTimes); history.needToBePlayed.Add(currentPlayerHistory); currentPlayerHistory = new History.PlayerHistory(); currentSceneState.players.Remove(player); Debug.Log("Player is dead"); }
public void respawnWith(History.PlayerHistory history) { this.playerHistory = history; isRespawned = true; }
private void OnDestroy() { currentSceneState = new SceneState(); currentPlayerHistory = new History.PlayerHistory(); }