/// <summary> /// Sets the files of the gameObject according to the last stored state /// </summary> void PopState() { if (states.Count > 0) { // pop the state from the list int lastIndex = states.Count - 1; KnightTimeState prevState = states[lastIndex]; states.RemoveAt(lastIndex); // Resurrect if currently dead if (isDead && !prevState.isDead) { Resurrect(); } // set the fields according to the current state rb2d.position = prevState.position; rb2d.velocity = prevState.linearVelocity; facingRight = prevState.facingRight; jumping = prevState.jumping; canMove = prevState.canMove; isDead = prevState.isDead; jumpMultiplier = prevState.jumpMultiplier; keyAudioTimer.Duration = prevState.keyAudioTimerSecondsLeft; jumpOnEnemyTimer.Duration = prevState.jumpOnEnemyTimerSecondsLeft; if (hasKey && !prevState.hasKey) { // put the key back keyObject.GetComponent <Key>().RemoveOwner(); } hasKey = prevState.hasKey; if (prevState.finishedJumpedOnEnemy && !finishedJumpedOnEnemy) { // Audio in reverse reverseAudioManager. CreateReverseAudioSource(AudioClipName.JumpOnEnemy); } finishedJumpedOnEnemy = prevState.finishedJumpedOnEnemy; if (prevState.pickedUpKey && !pickedUpKey) { // Audio in reverse reverseAudioManager. CreateReverseAudioSource(AudioClipName.KeyPickUp); } pickedUpKey = prevState.pickedUpKey; } else { // pause audio AudioManager.Pause(); audioIsPaused = true; // do nothing, like nothing is moving } }
void PopState() { int lastIndex = states.Count - 1; if (lastIndex > -1) { ChestTimeState lastState = states[lastIndex]; states.RemoveAt(lastIndex); if (!lastState.isOpen && isOpen) { Close(); } if (lastState.finishedOpening) { reverseAudioManager. CreateReverseAudioSource(AudioClipName.ChestOpen); } finishedOpening = lastState.finishedOpening; finishedOpeningTimer.Duration = lastState.openingTimerSecondsLeft; } }