Creating Collectibles in Unity
Making our collectibles for our 2.5D game
Objective: Implement collectibles in our 2.5D game.
The Functionality
The first thing I did was ensure my collectibles in the scene had a Collider, with isTrigger set to true, and a RigidBody with Use Gravity set to false. I then gave these collectibles a custom C# script I named CoinController. This is the code I have in that script:
As can be seen, we have another script called PlayerController, and we use it to call a method called AddCoin(). This is the code for that method:
Pretty simple. All it is doing is incrementing an int field and calling a method in our UIManager class to update the coins UI. I implemented my UIManager class as a Singleton, and here is the code for how I got it all done:
With all of this hooked up, I got the result we see here:
Not too bad if I do say so myself. That’s all for this article. Thanks for reading! In the next article, I will implement some moving platforms.