Phase 2: Boss AI Part 2
Objective: Set up the initial states for the Boss AI
We start by creating a public enum called BossState and set some states. For now we will have Arriving, Spawning, Recharging and Won. We create a public BossState called currentState, We set the current state in the Start method to Arriving as when the wave ends and the Boss is instantiated it will be just at the top of the screen and barely visable so arriving will be the Boss slowly coming into the scene and stopping halfway down. We also need a connection to the player for other states so we create a Player component, assign and null check it using find and get component in the Start method.
Next within the Update method we run an if check to see if the player is null and if so set the currentState to Won. After that we use a switch for the currentState. We use a transform move towards to get the boss from the instantiated position to center screen then on that position trigger the next state which is spawning.
Spawning starts a coroutine that spawns two enemies one coming out of each side of the Boss ship and rotating and continuing on as normal. Once spawned the state is set to recharging(we will add more weapons like lasers and movement later) and moves back up to the top of the screen. On reaching the top it triggers the arrival state again and these states loop until the player is destroyed.
In the next post, we will add more states including more attacks and a Boss health/death state.