Smart Enemy

Jason Schneider
2 min readJan 22, 2022

We already have an Enemy with a turret which targets and fires at the player. Let’s create an Enemy that knows when it is behind the Player, that will deploy a back facing turret and fire it.

To accomplish this, lets create another script called; EnemyWeaponBackFire and add the following:

We then, of course, need to drag our weapon sprite and laser object into their respective fields; once positioned and scaled correctly on our Enemy object.

We then need to reference this script in our Enemy script, and add the following to the Enemy script:

Need to also add _enemyWeaponActive as a bool variable.

Saving the script, jumping back into Unity, pressing play and then pause. Then setting the spawned Enemies, Enemy Weapon Active to true and pressing pause again, will give:

Great, now we just need to decide which Enemies will have this ability and and set _enemyWeaponActive to true when spawned. This I will leave to you.

--

--