Adding the final details
Two things are missing here: the Enemy is not shooting any bullets and it doesn't have animations. Let's start by fixing the shooting issue:
- Add a
bulletPrefab
field of theGameObject
type to ourEnemyFSM
script and a float field calledfireRate
. - Create a function called
Shoot
and call it insideAttackBase
andAttackPlayer
: - In the
Shoot
function, place code that's similar to the code we used in thePlayerShooting
script to shoot bullets at a specific fire rate, as shown in the following screenshot. Remember to set the Enemy layer in your Enemy Prefab, in case you didn't previously, to prevent the bullet from damaging the Enemy itself. You may also want to raise the AI script a little bit to shoot bullets in another position or, better, add ashootPoint
transform field and create an empty Object in the Enemy to use as the spawn position. If you do that, consider making the empty...