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.

--

--

--

Unity developer with a love of learning all things programming.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Topics: Mongodb overview, mongoose, mongodb queries

Pros and Cons of Web Development Frameworks

CS373 Fall 2021: Nathan Eisenberg: Final Entry

Pattern Matching in TypeScript with Record and Wildcard Patterns

Dart Features for Better Code: Types and working with parameters

Inserting security in Github pull requests! — Part 2 (using Github Actions)

Creating personal emoji

Framework 1: Level Refinement

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
Luke Duckett

Luke Duckett

Unity developer with a love of learning all things programming.

More from Medium

Quick tip — How to set up Occlusion Culling in Unity

P4: Creating a Gritty Office Den

Post Processing in URP for Unity 2020

My journey becoming a Unity game developer: Make a game look beautiful-Scifi Control Room Floors