Nerd For Tech

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/.

Enemy Got Shield Buff!- Game Dev Series 46

S.J. Jason Liu
Nerd For Tech
Published in
3 min readJun 11, 2021

--

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.

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

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/.

S.J. Jason Liu
S.J. Jason Liu

Written by S.J. Jason Liu

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

No responses yet