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.

--

--

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