2D Galaxy Shooter — New Enemy Type: Shielded Enemy

Marcus Cohee
2 min readSep 29, 2021

--

Hello all!

Today, I will go over how to make a Shielded Enemy! See below!

Creating the Shielded Enemy

I changed things up with this Enemy type and made it a drone instead.

  1. Drag an Enemy prefab in hierarchy.
  2. Unpack the prefab.
  3. Rename it Shielded_Drone_Enemy.
  4. Add any sprite to the Sprite Renderer.
  5. Remove and reapply the 2D Polygon Collider so it has the correct hitbox.
  6. Make a new C# script named ShieldedDroneEnemy.
  7. Remove the Enemy script, and add the new script.
  8. Re-reference the audio source, prefabs, and such.
  9. Add a shield to the new enemy making it a child, rename it Enemy_Shield, resize and position it where it covers the whole enemy, then change the shield sprite to red to indicate it can only take one damage.
  10. Add it to the Prefab folder.

ShieldDroneEnemy Behavior

In our behavior, it will be similar to the original Enemy prefab but will have 2 lives.

  1. Open both the Enemy and the new ShieldedDroneEnemy scripts.
  2. Copy everything from the Enemy script to the new one.
  3. Create variables:
    [SerializeField] private GameObject _enemyShield;
    [SerializeField] private bool _isShieldActive = true;
  4. Reference the Enemy_Shield in the Inspector.
  5. In Start(), set the _enemyShield and _isShieldActive to true. This will make sure the Enemy always spawns with an active shield.
  6. In the OnTriggerEnter2D() method, modify AddScore(10) to AddScore(50).
  7. In the EnemyDeath() method, add this if statement. It is saying that when damaged, instead of destroying the object right away, set the shield to false and return to the top, not activating the death sequence.

That was how to add a shield to an enemy! Next, now that I have enough enemies, I will make a wave system in the SpawnManager!

Thank you for your time!

--

--

Marcus Cohee
Marcus Cohee

Written by Marcus Cohee

I am starting Unity and learning the ropes as I go! Let’s take this journey together!

No responses yet