Adding the final details
We have two things missing here: the enemy is not shooting any bullets, and it doesn’t have animations. Let’s start with fixing the shooting by doing the following:
- Add a
bulletPrefabfield of theGameObjecttype to ourEnemyFSMscript and afloatfield calledfireRate. - Create a function called
Shootand call it insideAttackBaseandAttackPlayer:

Figure 9.67: Shooting function calls
- In the
Shootfunction, put similar code as that used in thePlayerShootingscript to shoot bullets at a specific fire rate, as in Figure 9.68. Remember to set the Enemy layer in your Enemy Prefab, if you didn’t before, to prevent the bullet from damaging the enemy itself. You might also want to raise the AI GameObject position a little bit to shoot bullets from a position other than the ground or, better, add ashootPointtransform field and create an empty object in the enemy to use as a spawn position. If you do...