private void UpdateDoorOpeningPhase() { switch (doorOpeningPhase) { case DoorOpeningPhase.None: break; case DoorOpeningPhase.MovingTowardsDoorNode: nav.destination = doorNode.position; if (nav.remainingDistance < nav.stoppingDistance) { doorOpeningPhase = DoorOpeningPhase.OpenDoor; FreezeNavMeshAgent(); TransitionWalkToIdle(); } break; case DoorOpeningPhase.OpenDoor: if (aiStateBeforeDoorOpeningPhase == AIState.Chasing || aiStateBeforeDoorOpeningPhase == AIState.PermanentChase) { for (int i = 0; i < doorScriptList.Count; i++) { doorScriptList[i].BreakTheDoor(transform.forward); } // Reset door opening chase (because we are breaking the door(s) we don't // need to proceed to WaitingForDoorToOpen) doorOpeningPhase = DoorOpeningPhase.None; // Reset timer openingDoorTimer = 0f; // Return to monsters' previous state aiState = aiStateBeforeDoorOpeningPhase; SetChaseSpeedInNavMeshAgent(); TransitionIdleToChase(); } else { // Open the door(s) for (int i = 0; i < doorScriptList.Count; i++) { doorScriptList[i].Open(); } // Move to the next phase doorOpeningPhase = DoorOpeningPhase.WaitingForDoorToOpen; } break; case DoorOpeningPhase.WaitingForDoorToOpen: openingDoorTimer += Time.deltaTime; if (CheckMonsterSenses()) { for (int i = 0; i < doorScriptList.Count; i++) { doorScriptList[i].isUsedByMonster = false; } // Reset timer openingDoorTimer = 0f; doorOpeningPhase = DoorOpeningPhase.None; } if (openingDoorTimer > openingDoorTime || doorScriptList[0].CurrentDoorState == Door.DoorState.FullyOpened) // Note: We just need to check the one door { doorOpeningPhase = DoorOpeningPhase.None; // The door is not used by the monster anymore for (int i = 0; i < doorScriptList.Count; i++) { doorScriptList[i].isUsedByMonster = false; } // Reset timer openingDoorTimer = 0f; // Return to monsters' previous state aiState = aiStateBeforeDoorOpeningPhase; SetNormalSpeedInNavMeshAgent(); TransitionIdleToWalk(); } break; default: break; } }