Adding shields to enemies

Let’s go over the implementation of randomly adding a 1 hit shield to enemies.

In this article I added a shield to the player and we will use similar logic for the enemies.

Open up the enemy script and add a GameObject for the shield, a bool to check if it is enabled or not. Also add a SpawnManager to be able to check what the current wave is to ensure shielded enemies are not showing up too early in the game.

Initialise the SpawnManger in the Start function and add an if statement to check if the wave number is high enough. If it is high enough, randomly enable the shield:

Add the function for enabling the shield:

When the enemy gets hit by the player or by the projectile, disable the shield:

Lastly, add the shield object to the enemy prefab:

Good luck!

--

--

--

Unity / C# Game developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How I Debugged A Cyberpunk 2077 Crash

How to setup a single node Prefect Server

Python Tricks, Inheriting from Built-in data types

Let’s Create a Shakespearean Insult Generator in Python

Programmer Meetups — Not as Awkward as You Think

Redis 5.X under the hood: 3 — Writing a Redis Module

Software Developer Vs. QA Engineer/Tester

Understanding Mobile App Development Cost- Cost Breakdown

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Niklas Bergstrand

Niklas Bergstrand

Unity / C# Game developer

More from Medium

28VC | Blockchain in Medical Industry

SFIL’s Blueprint for the Future

What is WODL

Initial Game Offering — What Is An IGO All About?