Framework: Win and Loose Condition.
Objective: Implement win and Lose conditions.
The first step is to create two variables in Pool Manager,_amountOfAIBreach, and _totalAI.
Then go to the start method and initialize the above variables equal to amountOfAI.
Create a public method Called EnemyReachDestination, in this method we want to implement a condition when 50% of the enemy reaches the destination we enable a loose screen.
So each time the enemy reaches the destination we increment _amountOfAIBreach, then we check if amountOfAIBreach is equal to _amountOfAI divided by two, if this condition is true we enable lose canvas and enable Fade in transition which I made using a timeline, go to the previous article about the timeline. And I call Coroutine to deactivate other AI since It won't make sense for other AI to keep moving or shoot the Player at this point or do another thing if the screen goes black.
To deactivate all enemies if we lose, I check if any enemy is active in the array objects in pool Manager then I deactivate it.
To enable wind conditions we need to kill All AI, we do this by going to the EnemyCount method. Then we check if _remainingAI is less than 1, this means if is less than 1 we killed all AI.
This method I create in the previous articles when I create HUD control if you have been following my recent article.
Last we call EnemyReachDestination when the enemy reaches the destination which means when _isagentReachDestination is true in the enemy script.
This is how to Implement Loose and Win Conditions.
See you in the next one.