Pick Up Everything!- Game Dev Series 80

Objective: create script to collect objects in game.

Collectables in platformer game mean a lot. Mostly, they are the biggest achievement that players pursuit.

In this article, we will create the function of collectable that allow Player to collect and update the counts to UI.

Update the scene

Before we coding to add these function, we need to update the scene.
First, I changed the name of collectables to coin, just like what we get in Super Mario Bro.
Second, create a Canvas with text object. This is where we are going to display the current coin counts.

Current game scene

With these done, we can start collecting these coins.

What should Player do

First thing first, we will define the meaning of coins to Player. In Player script, create an integer variable to store coin counts. And also create a public method to calculate the total counts of coin that we collected.

What’s more in this method is to update the coin to UI, which will be done when we finished created the script of UI.

UI controller

Create a script called UIManager, and also create a public method to update coin text.

I have used Singleton to create UIManager. This would make it easier to access the public method in it.

Once we have the method to update UI, we can add one more line in Player.

And that is all for Player and UI. Time to collect these coins.

Those collectables

The function of collecting objects would be similar to the function we created to collect powerups in Galaxy Shooter.

Create a script and called it Coin. With this script, we will use OnTriggerEnter to detect if is Player collided with.

Once it collide with Player, make it communicate with the public method we created. And don’t forget to do the null check to prevent compiler error.

After communicated, this gameobject should be destroyed.

All done! Back to editor and assign the text gameobject to Canvas, and everything would works now!




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

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

Recommended from Medium

Unity vs SceneKit: which tool you should use to build your ARKit app

Lateral Movement — SCM and Dll Hijacking Primer

Test Automation Using Pytest and Selenium WebDriver

Getting Started With Apache Airflow

Cypress and GraphQL

Dart’s Single-Threaded Concurrency Model: Isolate

Recommended Books for every Data Engineering and Data Science Professional

Development of the MADOCA to EPICS Gateway

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
S.J. Jason Liu

S.J. Jason Liu

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

More from Medium

Tap & Hold & Rapid Prototyping w/ New Unity Input System

Day 105: Working with Animation Events in Unity

2D Mobile: Designing Enemies Using Abstract Classes

Adding Game Over UI elements