Collectables
All objects in a game that the player is able to collect are called collectables. Probably, you are a gamer yourself and this concept should be fairly familiar to you. In our game, we will add collectable coins scattered in the level's pieces for the player to collect. I am not going to talk too much about what collectables are and why it is good to use them as I believe it is pretty obvious. Let's skip all that and make a simple plan:
Our collectables—let's call them coins from now on—will be collected on contact with the player game object
We will write the
Collectable
class to manage coin behaviorFor every coin collected, we will count and increment the number of collected coins on the UI
The count of total collected coins will restart with the new game