Menu
CoddyTech

Recap: Loot Table

Part of the Game Architecture in Unity section of Coddy's Unity journey. Lesson 21 of 64.

challenge icon

Challenge

Easy

Fill the chest's loot table to match the scene.

  1. Declare public enum Rarity { Common, Rare, Epic, Legendary } and a [System.Serializable] class LootEntry with public string itemName, GameObject prefab, Rarity rarity.
  2. Give the chest public List<LootEntry> table;.
  3. Write public int WeightOf(Rarity rarity): Common 10, Rare 4, Epic 2, Legendary 1. public int TotalWeight() adds them over table.

Press Play: nothing drops yet. Then Check.

Try it yourself

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class LootChest : MonoBehaviour
{
}

All lessons in Game Architecture in Unity

Practice on your own: Unity playground