I think you dropped something — Creating a simple loot drop system in Unity2D

In this quick article I’m going to show you how to set up a system to drop loot on destroying an enemy where the award can be adjusted based on a setting.

In my starting scene I have an enemy set up which can take damage and eventually die. When the enemy dies I want it to drop a diamond which holds a certain point value, which will add to the players tally, this will be adjustable in the inspector.

We will set the player script up to store and receive diamonds.

The next script will be the diamond script. This is going to be attached to a diamond sprite which has a box collider 2d (trigger) component.

The script has a function allowing the diamond value to be set. When it collides with the player it will reward these points and be destroyed.

The next step is to create the function on an enemy script which will assign this value and spawn the diamond in the death function.

And now we can test our functionality.

That's all for now.

--

--

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