Since our enemy code is currently modular, all we need to do is create a function called something like PowerupHunting() and place it into every enemy's case. This is really nice since maybe you don’t want a particular enemy to behave that way for whatever reason. I’m finding modularizing behaviours can add a lot of variety to my enemies actions if I choose to create new ones and I can mix and match them.
So let’s take a look at PowerupHunting!
Raycasting will draw an invisible line from your enemy to a length you specify. In my case, I put 10 units down. We put the raycast into a variable called hit which is then either true or false; we then do a check to see if there is ever a hit, and if whatever collides with that Raycast has the PowerUp tag, it will immediately fire a set of really fast lasers!
Aggravating! But let’s give our enemies a fighting chance, no? Yeah, no. But we’ll put it in any way. :) Tomorrow we’ll give the player a fighting chance by pressing C, he’ll be able to attract the powerups and we’ll do that using a thing called the observer pattern using Delegates and Events!