Let’s Loot Enemies- Game Dev Series 108

Objective: create loot system.

When we have a fully functional enemy, it is time to add some prize that Player can collect.
In this article, we will create a loot system.

Function of diamond prefab

First we need a diamond prefab as prize. Create a diamond prefab from sprite with shining animation. Once prefab is ready, create a script and attach to it.
We will make this prefab be collectable by Player and add diamond amount to Player.

Create this “AddDiamond(int)” function to Player script.

Now we need to add the reference of diamond to all the enemies.
Open Enemy script and add another variable.

Back to inheritance enemy script and instantiate the prefab after death.

Set the gems integer in editor, and the enemy would drop the number of diamond(value) after death.

Copy the last 2 lines to all enemies and do the same setting, then everything would be done!

--

--

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
S.J. Jason Liu

S.J. Jason Liu

99 Followers

A passionate gamer whose goal is to work in video game development.