I have already created a system of collectibles, today I am expanding it for the mobile game I am making.
In this game, we have gems as currency, more specifically diamonds.
I need to create a system that allows me to get diamonds when enemies are killed and that the diamonds can be collected by the player that in the future we will spend in our shop that I am making.
First, we are going to make the prefab of the diamond that must have its animated sprite and the script that recognizes the player and updates the value of the gems obtained.
Spawn and update the value
For the spawn once created the prefab is enough to associate it to the scripted enemy so that all types of enemies can use it, but we must update at the appropriate time the value of the diamond that we are going to instantiate in the scene. Because according to the enemy that is killed a diamond of a different value appears.
In our Enemy class, we have inserted the value that a gem will have so we only need to access the script of the single diamond that is instantiated and update its value parameter with that of the creature that is defeated