Feature: Negative Power Up

This article will show how to make a Power-Up that will negatively affect the Player if it is collected. The negative effects will be the loss of one health and an increased fire delay for the Power-Up duration.

In the Player script, we need a few variables. The first is a float for the amount to increase the fire delay. The second is another float, so we know how long the negative effect should last, and the final variable is a bool, so we know when the negative effect is active.

In Start, we need to set the negative effect duration to the base Power Up duration.

In the FireLaser method, we need to implement the fire delay increase when the negative effect is active by adding it to _canFire.

The _canFire variable determines if we can fire, which is covered in the Cool-Down system article.

Next, we need a Coroutine to tick down the negative effect duration to zero, then reset it back to the base Power Up duration, and turn off the negative effect.

We need a public method that the Negative Power Up will call to activate the negative effect, immediately affect the fire delay, and start the Coroutine. But if the effect is already active, we will increase the duration.

In the PowerUp script, we need to add a new element to the Enum for the Negative Power Up.

And finally, add a case to the switch for the Negative element, where activate the negative effect and take one health from the Player.

In Unity, we need to create the Negative Power Up Prefab for the Player to collect.

In Play Mode, we can see the Negative Power Up effect working when the Player collects it.

--

--

--

Unity Developer, Software Engineer, Game Developer

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

Recommended from Medium

Serverpilot : Easiest way to Setup | Manage | Secure your PHP Website with Amazon Cloud EC2 Servers

B2B Customer Self Service Portal

Responsive Reflective

Text to SQL Queries

The rise of the Biz Dev and gaining speed as well autonomy

reaching for the stars with power automate — credit: Mo, yes this is my doing

DOS Assembly 101

Image Credits : Internet

Standard Coding Style

Kamu Update: Web UI, GraphQL API, RFC Process, and Web3

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
Kyle W. Powers

Kyle W. Powers

Unity Developer, Software Engineer, Game Developer

More from Medium

Drawing rectangles

Destroying objects!!!

Doing basic unit testing in Unity/C#

O of N Log N method