2.5D Game Development In Unity: Collectibles

In this article I’ll set up a simple collectible and go over how to display this using a UIManager.

I’ve created a simple sphere game object to represent a coin. I created a coin script and attached it to the sphere. The sphere has to have a rigidbody component for the collision detection as well as a trigger collider. Be sure that Using Gravity false.

In the script I am just destroying the coin once the player collides with it, but before that I am having a heper method in the Player script referenced to add to the number of coins collected. This helper method just takes a “coins” variable and increments it by saying _coins++;.

I also have a refence to the UIManager called _uiManager. I have a method set up in another script called UIManager called UpdateCoinDisplay and Im feeding it the coins parameter.

All thats left to do now is create the UI text components and assign them in the inspector for the UIManager on the canvas game object.

You’ll see here that I also have a lives UI object as well. I’ll get into that later, but I’m sure you can figure it out ;). Its the exact same set up as the coins.

Now whenever the Player collects a coin, the UI will update accurately.

--

--

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