Adding final details
We have two things missing here, the Enemy is not shooting any bullets and it doesn't have animations. Let's start 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 18.39 – Shooting function calls
- In the
Shootfunction, put a similar code as the one used in thePlayerShootingscript to shoot bullets at a specific fire rate, as in the following screenshot. Remember to set the Enemy layer in your Enemy Prefab, in case you didn't before, to prevent the bullet from damaging the Enemy itself. You might also want to raise the AI script a little bit to shoot bullets in another position or, better, add ashootPointtransform field and create an empty Object in the Enemy to use as a spawn position. If you do that, consider making the empty Object to not...