Create a Loot System in Unity

To create a system that allows 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.

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.

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 the 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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store