Nerd For Tech
Published in

Nerd For Tech

Enemy Got Shield Buff!- Game Dev Series 46

Objective: Create 1 time protection shield to enemy.

I QUIT!

Every challenge is a good opportunity improving the skill to defeat a game. To raise up the level of challenge, giving our enemies some buff might be a good start.

In this article, we will make our enemy got shield protection randomly. It is getting tougher for our players to clear them all.

Shield prefab

First thing we need to do is to create a shield prefab, which we can easily create one from the Player.

Inside our Player, there is a shield gameobject which is not a prefab yet. We can simply drag it into Project as a new prefab.

Then we need to attach this shield prefab into the Enemy prefab.

We should deactivate it in prefab and call it later in the script.
With this, we can randomize it in the script.

Randomly shield setting

In this script, we will need 2 variables to use shield.

In the Start(), we will let the God of Random to decide who should get the shield.

In this random rule, only 1 of the 3 would get the shield.

Then we also need to adjust 2 method to enable the shield effect.

First is the LaserHit().

We shall do the shield test first. If it is protected by shield, then disable the shield, which is what we need for a 1 time protection.

Use the same statement in OnTriggerEnter2D().

All done! We can play it now to see who would be the lucky one.

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

Directory Traversal — what is it?

Razorpay payment DJANGO

Let’s Migrate Symfony Project to Kubernetes!

Prepare your Mac for Java Spring Microservice Projects: Install JDK, Brew, Maven, and IntelliJ

Why Is Android Development Such A Meadow Of Fxckeries?

How to do rolling count distinct in BigQuery? Analytic function is not a good solution

Cloud Utilisation in the Banking Sector — part 1

GitLab E2E Pipeline — Logger Application+ELK Stack Deployment Using Terraform+Ansible on AWS

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Cleaning up the Homing Missile code

My journey becoming a Unity game developer: 2.5D Infinite Runner-URP and Player’s 3D model added

Creating a HUD

Hidden Shortcuts to Make Level Design Easier in Unity.