Nerd For Tech
Published in

Nerd For Tech

Powerup collector

Now that we have all of the powerups that we want in place, let’s create a quick feature that will allow the player to collect them from where ever they are. This will allow the player to play a bit safer, but we will look into adjusting how strong it is later on when we allow our enemy units to shoot at the powerups.
To start, we need to go into our player script and create a new gameobject to work with for the player to be able to drag in the powerups:

From here, we can go into our void update and create a new method to work with:

As to how we will make our powerups move towards our player, we will go into our powerup script and have create a code that will have it move towards our player, which we will use in the future again for a new enemy type:

Before we create the movement method however, we first need to create a collection method that will allow us to call the powerups to us. We will also need to create a coroutine that will be called upon to end our powerups movement towards the player after a couple seconds.
Finally, we can create the method in which our powerup has destination when we press our C key:

With our MoveTowards method, our powerups will make the movement to our player. With all of this done, we can now look at how it appears in game.

There we have it, our player can now call upon powerups, however we have to be careful for the pesky Mag powerup, because it will be just as attracted to us as our others.

--

--

--

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

How I earned $1200 on a bounty program :O

Understanding Billing in Google Cloud Storage

Understanding OpenKruise Kubernetes Resource Update Mechanisms

17 Must-Read Resources for Windows App Developers

Are you REALLY automating your infrastructure?

What is this “DevOps” thing, and why should I care about it?

This image comprises the cultures and practices that define DevOps.

Truth and Floating Point Woes in Python

Sqoop Import from MySQL to Hive & HBase

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
Jordan Evans

Jordan Evans

More from Medium

Creating a Physics Based Character Controller from Scratch in Unity

Basics of Optimization in Unity

For Loops | C#

Improving Upon Selection Highlighting in Our Game — Part 3