Nerd For Tech
Published in

Nerd For Tech

Collecting stuff

Objective: make the coins collectable

In order to have a true platform game, we have to collect coins or whatsoever. Since both coins and player have a collider it will be very simple.

Let’s create a separated script for the player CollectionManager.

As usual, we are going to switch on the tag. For now let’s focus on coins: when we enter its trigger we make a call that would destroy the collectible and add a coin-value (stored in a CollectibleStats script attached to the coin) to the PlayerStats (another simple script just holding values and method for changing them). The destruction must be performed on the collider object, but also on its parent (if present, remember that null parent means no parent), because the coin true object is stored in an empty parent.

The AddCoin method would then add the value and update the UI, by making a call on a singleton UIManager script.

In the future, we will just need to apply the same logic to each collectable (lives, different coin, power up…).



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