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
bulletPrefab
field of theGameObject
type to ourEnemyFSM
script and afloat
field calledfireRate
. - Create a function called
Shoot
and call it insideAttackBase
andAttackPlayer
: - In the
Shoot
function, put a similar code as the one used in thePlayerShooting
script 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 ashootPoint
transform 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...