public void CreateMemento(Transform checkPointTransform) { if (liveAdded) { GameManagerScript.instance.playerStats.lives--; liveAdded = false; } lastPlayerScore = GameManagerScript.instance.playerStats.points; collectedCoins.Clear(); collectedPowerUps.Clear(); checkPointMemento = new LevelMemento(); checkPointMemento.checkpointPosition = checkPointTransform; checkPointMemento.collectedCoins = collectedCoins; checkPointMemento.collectedPowerUps = collectedPowerUps; checkPointMemento.canJump = canJump; checkPointMemento.canMoveLeft = canMoveLeft; checkPointMemento.canMoveRight = canMoveRight; checkPointMemento.canTeleport = canTeleport; checkPointMemento.canClone = canClone; }
public void RespawnPlayer(LevelMemento memento) { if (GameManagerScript.instance.playerStats.lives > 0) { GameManagerScript.instance.playerStats.lives--; GameManagerScript.instance.gameStats.dieCount++; GameManagerScript.instance.playerStats.dieCount++; GameManagerScript.instance.NotifyObservers(); GameManagerScript.instance.SaveStats(); player = Instantiate(playerInst, memento.checkpointPosition.position, memento.checkpointPosition.rotation).GetComponent <Player>(); } else { GameOver(); } foreach (var coin in memento.collectedCoins) { coin.SetActive(true); } foreach (var powerUp in memento.collectedPowerUps) { powerUp.SetActive(true); } foreach (var platform in platforms) { platformSpawner.SpawnPlatform(platform); } canJump = memento.canJump; canMoveLeft = memento.canMoveLeft; canMoveRight = memento.canMoveRight; canTeleport = memento.canTeleport; canClone = memento.canClone; DecoratePlayer(); GameManagerScript.instance.playerStats.points = lastPlayerScore; }