Sitemap

How to Spawn Loot from a Chest.

3 min readJul 30, 2025

--

Objective: How to spawn a Loot from a chest.

In the first step, create a chest script, add this variable, and get the animator on Aweke.

Press enter or click to view image in full size

Go to the Interact method, check if this chest is not locked, using _isLocked variable. Then set _isOpen to false when it's true and set it to true when it's false., Then set the bool for the chest animator.

Note: By default, I will set _isLocked to false

Press enter or click to view image in full size

Create a script called SpawnLoot and attach it to the Chest, then add these variables.

Press enter or click to view image in full size

Create a two-bool and a method called Loot, then check if isSpawned is true and canCollect is false, then set isSpawned to false, then call the Loot method.

Press enter or click to view image in full size

Go to the Loot method, the first thing you need to turn _canCollect to true, then create a random number. Below the random number starts a coroutine called Create LootItems.

Press enter or click to view image in full size
CreateLoot will be responsible for create the item.

Go to the CreateLoot Method, then create loot and position it at the spawnPoint position.

Note: I'm sorry, I am not going to explain in a beginner's way, but if you have a question, please leave a comment, and I will explain it to you.

Press enter or click to view image in full size

Go to the Chest script, inside the Interact method, then get SpawnLoot, then use its handle to change isSpawned to false, to not allow it to spawn again when the object is spawned and not collected.

Press enter or click to view image in full size

Create a prefab of any type, then add it to the List of LootItem in the inspector. Then, don’t forget to add the Interact script and other components required to work, such as the sphereCollider, as we discussed when I started this project.

Finally, I will add behavior to allow loot to drop. Here is the script for the object. This Item will have a rigid body and a box collider.

Press enter or click to view image in full size

Let's play the editor. Ask me any questions about this system if you feel you need more info about some logic. I am happy to help!

Press enter or click to view image in full size

See you next one.

--

--

Suleiman Abdullah
Suleiman Abdullah

Written by Suleiman Abdullah

My name is Suleiman Abdullah. Im learning game development and share what I learn by writing articles. :https://ko-fi.com/suleimanabdullah