When we have a fully functional enemy, it is time to add some prize that Player can collect.
In this article, we will create a loot system.
Function of diamond prefab
First we need a diamond prefab as prize. Create a diamond prefab from sprite with shining animation. Once prefab is ready, create a script and attach to it.
We will make this prefab be collectable by Player and add diamond amount to Player.
Create this “
AddDiamond(int)” function to Player script.
Now we need to add the reference of diamond to all the enemies.
Open Enemy script and add another variable.
Back to inheritance enemy script and instantiate the prefab after death.
Set the gems integer in editor, and the enemy would drop the number of diamond(value) after death.
Copy the last 2 lines to all enemies and do the same setting, then everything would be done!