Spawning Enemy with Shield

Day 45- Making 2D Space Shooter Game

Objective: Making enemy spawn with shield which allows them to take one more damage

First we need to create a variable to store the shield and a bool variable to detect if the enemy has shield during spawn or not.

Now we don’t want this enemy to always have shield, instead we want the enemy to have 10% chance of spawning with a shield

We take the random number and if it is 5 then the enemy will have a shield during spawn. Note to write this code in Start.

Lastly create a condition to ignore one hit from player or laser and set the shield to inactive during that process.

Now the enemy can take one extra damage which will set the shield as inactive and the next time the enemy will get destroyed.

--

--

--

Unity Developer

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

Recommended from Medium

What is the Parallax Effect? and how to implement it using CSS.

Creating Collectibles for Unity

My Review of Harvard CS50

How to use Git for the first time; Commit, Push, Clone.

git logo

Flutter Clean Architecture Series — Part 2

Developing and Building RN App with Expo

On sheet metal unfolding (Part 1)

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
Niraj Karki

Niraj Karki

Unity Developer

More from Medium

Loot System: Part Two — Enemy Loot!

Creating Elevator in Unity — Part 3: Moving Elevator.

Using Post Processing Volumes in Unity3D with the URP

Quick tip — Upgrading your Unity project to Universal Render Pipeline (URP)