Creating collectibles

Jaime
Oct 22, 2021

If you have implemented it before in one game, you probably will do it in another game. In the past, I created a power up collectible in SpaceShooter: https://gamedevbox.medium.com/creating-modular-power-up-systems-in-unity-b0b012032ef1

I will just need to do the same thing here as well. In this case, the Player will be collecting coins and the screen will be updated with the coins already collected.

The collectible should have a Collider set to Is Trigger and have a Rigidbody.

Using delegates, we simply send a message to any object that listens and then destroy itself:

The Player will listen and add coins to _coins and then send a message to any object that listens on the latest value of _coins:

Finally, the UIManager will be listen to it and update the text UI with the latest value of _coins:

Now, collectibles are implemented:

--

--