Creating Collectables in Unity
Objective: Create items the player can pick up and collect.

First we’ll make sure our collectable item has a Collider component and Is Trigger is checked. We’ll also need a Rigidbody component, and will probably want Use Gravity unchecked, unless we want the collectable to fall to the ground.

Now we’ll create the Collectable script to attach to our collectables. We’re creating coins in this case, so we’ll give them a _value that can be assigned in the Inspector. In this way, we can create coins of different denominations.
When the player touches our collectable, the collectable will call the UIManager’s AddCoins method, passing-in the value of the coin. The collectable will then destroy itself. If we wanted to add particle or sound effects to the pick-up, we would place them just before the Destroy command.

The UIManager’s AddCoins method adds the coin’s value to the current count, then calls its UpdateCoinDisplay method, which updates the text with the new count.

In a more complex game with more collectables, we might use a Game Manager to track the items collected, and have it tell the UIManager what to update.