Phase 1: Ammo Collectable

Now that we have limited the amount lasers the player can have, we should create a collectable to reload the lasers.

Objective: Create a power-up that refills the ammo amount, allowing the player to fire again

First, we will create the collectable and name it Laser_Recharge. Also, adjust the size to match our other power ups’

Creating the Ammo Collectable

Next, we will add the powerup script since this will have the same behaviour as all the other powerups. I will assign it the power-up Id of 3 and assign the power-up audio.

Assigning the powerup Script
adding a comment in the script

After the script is assigned we will add the rigid body and collider components.

Adding the components

Now that we have the collectable created and set up we will move on to the scripts. In the player script, we need a method that will add 15 to the ammo count and update the UI manager. Also, set the can fire to true.

Laser recharge method

In the power-up script, we will need to add a case to the switch statement to call the LaserRcharge Method when collected.

Switch Statement

lastly, we will edit the Spwan Manager script so the Laser Recharge will be spawned along with the other power-ups. We will change the Random. Range to include the ID 3 which is what the Laser Recharge is assigned

Random Power Up ID

We will also add the Laser_Recharge to the Power Up Array.

Power Up Array

Let see this in action

Laser Recharge Demo

Happy Coding!




Unity / C# Game developer

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

Recommended from Medium

How I Convert website into android Webview

Android USB accessory

Jetpack Compose Custom Slider with Range Labels

Android background in a nutshell. Part 4 — RxJava

Using Dagger-Hilt in Android Project — A step toward clean architecture.

Dependecy Injection

Building an application using No Code platform: AppGyvr

💬Messaging App using Flutter (Blog — 5)

Improve your Gradle build times by disabling plugins

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
Bill Rislov

Bill Rislov

Unity / C# Game developer

More from Medium

How to install Express.js, here is the step-by-step guideline

Cold Shower Challenge

AP Exercises Jan 26

VEMP invasion P2E game Pirate X Pirate