Create a Loot System in Unity

Desired behavior:


  • Declare a public int diamonds variable in Player script
  • Declare a variable int gemsAmount (I will do it in Enemy base class but it can be done in each enemy script) and add this code snippets:
  • In each enemy:
  • in Damage (in Enemy script), if (Health <1), add:
  • In Diamond script declare also an int gems variable
  • In Diamond script, in OnTriggerEnter2D (don’t forget the ‘2D’ letters, remember it’s a 2D game, and if not, the trigger behavior won’t work), and check if other is player. Add:




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

Recommended from Medium

Why Document Capture is so Challenging?

Document Capture, Document Processing, Intelligent Document Extraction, Neutron, V2Solutions, Document Extraction

Merging AWS RDS Databases: (when) should we do it?

Shuffle a list C# (Fisher-Yates shuffle)

Container with Most Water

Creating a Simple Random Generator in Java

5 Best text editors for programming (2020)


Working With Pandas: Fixing Messy Column Names

How to use the Qualify Function in BigQuery SQL

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
Hernando Nieto Jaramillo

Hernando Nieto Jaramillo

Unity developer

More from Medium

Jumping in between two walls in Unity

Unity Interface Layout

Platformer: Player Animation VI — Roll

Using GameDevHQ’s FileBase Asset Database For HQ Models