Journal 104 — Unity 2D Mobile, Dungeon Escape Loot System with Diamonds
Objective: To add a loot system with collectible diamonds
In this article, I will go over the set up of the diamond collectibles.
First, we need to add the diamond sprite as a new game object. We can also create the diamond C# script.
After creating the diamond game object, we can make the sparkle animation and turn the diamond into a prefab.
After creating the prefab, we can add a Circle Collider 2D, Rigidbody 2D, and Diamond script.
Now we are ready to update the scripts.
Here are the results to check the diamond collectible works.
In each script, we can now instantiate a diamond when the enemy health drops to 0. We can make the instantiated diamond a game object variable, and update its gem value to the base enemy value. In this example, I have a gem value of 5 for the moss giant, 3 for the skeleton, and 2 for the spider.
Here are the results.
One last update is to make sure that if the enemy is dead, there is no way to spawn additional gems.
We can add a check in each Damage() function to simply return out of the function if isDead == true.
Thank you for your time!