/// <summary> /// State management for the prison fortress. /// </summary> private void UpdateFortressStates() { if (fortressState == EFortressStates.Dormant) { m_lightUp = false; m_warningCanPlay = true; m_spawningCanPlay = true; // sternPassengerSpawn.currentlySpawning = false; hullPassengerSpawn.currentlySpawning = false; timePassengerSpawnFor = m_rememberPassengerTimerValue; } if (fortressState == EFortressStates.Warning) { // Make sure the klaxon doesn't go on forever if (numberOfTimesKlaxonShouldSound > 0) { if (!m_mySource.isPlaying) { // This is just to make sure that Warning IS NOT invoked more than once in the update. if (m_warningCanPlay) { Invoke("Warning", 1.0f); m_lightUp = false; m_warningCanPlay = false; numberOfTimesKlaxonShouldSound -= 1; } } } else if (numberOfTimesKlaxonShouldSound <= 0) { // Change state fortressState = EFortressStates.Spawning; } //animation if (prisonAnim != null) { if (!prisonAnim.GetCurrentAnimatorStateInfo(0).IsName("OpenTrapdoor")) { prisonAnim.SetBool("Spawning", true); } } if (myLaser != null) { //Delay the laser to give the trapdoor time to open. Invoke("LaserOn", 1.75f); } } if (fortressState == EFortressStates.Spawning) { m_warningCanPlay = true; if (m_spawningCanPlay) { Invoke("Spawning", 4.5f); m_spawningCanPlay = false; } timePassengerSpawnFor -= Time.deltaTime; if (timePassengerSpawnFor < 0) { fortressState = EFortressStates.Dormant; m_timer = timeBetweenPrisonerDrops; //animation if (prisonAnim != null) { if (!prisonAnim.GetCurrentAnimatorStateInfo(0).IsName("OpenTrapdoor")) { prisonAnim.SetBool("Spawning", false); } } if (myLaser != null) { LaserOff (); } } // Reset the number of times the klaxon should sound numberOfTimesKlaxonShouldSound = m_rememberStartValue; } }
void Update() { ClampLights(); m_timer -= Time.deltaTime; // Check if it is time to begin dropping passengers if (m_timer < 0) { if (fortressState == EFortressStates.Dormant) { fortressState = EFortressStates.Warning; } } // State management UpdateFortressStates(); }